import java.util.Scanner;
/**
* @author 冰樱梦
* 时间:2018年12月
* 题目:求矩阵中各列数字的和
*
*/
public class Exercise08_01 {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
double m[][]=new double[3][4];
System.out.println("Enter a 3-by-4 matrix row:");
for(int i=0;i<m.length;i++){
for(int j=0;j<m[i].length;j++){
m[i][j]=input.nextDouble();
}
} // System.out.println("Enter the columnIndex");
// int columnIndex=input.nextInt(); int columnIndex=0;
System.out.println("Sum of the elements at column "+columnIndex+" is "+sumColumn(m,columnIndex));
columnIndex=1;
System.out.println("Sum of the elements at column "+columnIndex+" is "+sumColumn(m,columnIndex));
columnIndex=2;
System.out.println("Sum of the elements at column "+columnIndex+" is "+sumColumn(m,columnIndex));
columnIndex=3;
System.out.println("Sum of the elements at column "+columnIndex+" is "+sumColumn(m,columnIndex));
}
public static double sumColumn(double m[][],int columnIndex){
double total=0;
for(int i=0;i<m.length;i++){
total+=m[i][columnIndex];
}
return total;
}
}

求矩阵中各列数字的和 Exercise08_01的更多相关文章

  1. C++编程求数组中重复的数字

    题目:在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度为7的 ...

  2. Java:求字符串中邻接的数字为一个整体

    public static void main(String[] args) { String strNumbers = "0123456789";//用来进行判断数字的 Syst ...

  3. Maximal Rectangle, 求矩阵中最大矩形,参考上一题

    问题描述: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1 ...

  4. [LeetCode] Longest Line of Consecutive One in Matrix 矩阵中最长的连续1

    Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horiz ...

  5. [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  6. 搜索(DFS)---矩阵中的连通分量数目

    矩阵中的连通分量数目 200. Number of Islands (Medium) Input: 11000 11000 00100 00011 Output: 3 题目描述:   给定一个矩阵,求 ...

  7. 剑指offer 数组中的重复数字

    问题描述: 在长度为n的数组中,所有的元素都是0到n-1的范围内. 数组中的某些数字是重复的,但不知道有几个重复的数字,也不知道重复了几次,请找出任意重复的数字. 例如,输入长度为7的数组{2,3,1 ...

  8. c编程:求出4&#215;4矩阵中最大和最小元素值及其所在行下标和列下标,求出两条主对角线元素之和。

    //求出4×4矩阵中最大和最小元素值及其所在行下标和列下标,求出两条主对角线元素之和 #include <stdio.h> int main() { int sum=0; int max, ...

  9. Flex中对表格中某列的值进行数字格式化并求百分比

    1.问题背景 一般的,需要对表格中某列的数值进行格式化,对该数值乘以100,并保留两位小数,添加"%" 2.实现实例 <?xml version="1.0" ...

随机推荐

  1. 【leetcode 简单】第五题 最长公共前缀

    编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow" ...

  2. Entity Framework(EF的Database First方法)

    EntityFramework,是Microsoft的一款ORM(Object-Relation-Mapping)框架.同其它ORM(如,NHibernate,Hibernate)一样, 一是为了使开 ...

  3. Mysql储存过程7: case

    #用在储存过程中: create procedure k() begin declare number int; )); case number then select '>0'; else s ...

  4. ldconfig是一个动态链接库管理命令

    ldconfig是一个动态链接库管理命令 为了让动态链接库为系统所共享,还需运行动态链接库的管理命令--ldconfig ldconfig  命令的用途,主要是在默认搜寻目录(/lib和/usr/li ...

  5. ProxySQL 故障

    发现直接连接MGR节点是正常的,可以写入,但通过ProxySQL连接就无法show\select\insert 等 使用sysbench对ProxySQL报以下错误: FATAL: `thread_r ...

  6. MySQL之——如何添加新数据库到MySQL主从复制列表 【转】

    转自 转载请注明出处:http://blog.csdn.net/l1028386804/article/details/54653691 MySQL主从复制一般情况下我们会设置需要同步的数据库,使用参 ...

  7. linux配置samba服务【原创】

    转载请注明出处http://www.cnblogs.com/paul8339/p/7509981.html 需求,windows服务器访问linux的共享文件,需要linux服务器安装并配置samba ...

  8. 离线下载pip包进行安装【转】

    Host-A 不能上网,但是需要在上面安装Python-package 通过另外一台能上网的Host-B主机 1. 下载需要离线安装的Packages 在Host-B上执行如下命令: 安装单个Pack ...

  9. js事件、事件委托

    事件流 事件流:页面中接收事件的顺序: IE的事件流是冒泡流,其他的浏览器是捕获流,如下图: DOM事件流 DOM 事件流同时支持这两种事件流,并且规定DOM任何事件流都包含三个阶段:事件捕获阶段.处 ...

  10. C++——map注意事项

    1. C++标准模块库STL中提供了两种基本的关联容器:set和map.其内部实现是都是采用红黑树,但不同的是,set中结点存储的是键值,map中结点存储的是<key,value>的键值对 ...