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. zedboard学习记录.1.纯PL流水灯

    环境:vivado 217.4 开发板: zedboard ver.d xc7z020clg484-1 1.打开Vivado新建一个RTL工程. 2.add source->add/create ...

  2. PHP数据库类

    简单封装PHP操作MySQL的类 <?php /* 类的名称:Model 类的作用:连接数据库执行sql语句 作 者:lim 更新时间:20170812 */ class Model{ //存放 ...

  3. 宋牧春: Linux设备树文件结构与解析深度分析(1) 【转】

    转自:https://mp.weixin.qq.com/s/OX-aXd5MYlE_YoZ3p32qWA 作者简介 宋牧春,linux内核爱好者,喜欢阅读各种开源代码(uboot.linux.ucos ...

  4. Elasticsearch5.0 安装问题集锦【转】

    转自 Elasticsearch5.0 安装问题集锦 - 代码&优雅着&生活 - 博客园http://www.cnblogs.com/sloveling/p/elasticsearch ...

  5. 【转载】C#异常Retry通用类

    //Retry机制 public static class Retry { /// <summary> /// 重试零个参数无返回值的方法 /// </summary> /// ...

  6. vue单选,多选,多选的内容显示在页面可删除

    vue做单选只能选一个 <template> <div class="list"> <!-- 多行多列单选 --> <span>只能 ...

  7. 设计模式(一)工厂模式Factory(创建型)(转)

    原文链接:http://blog.csdn.net/hguisu/article/details/7505909 设计模式一 工厂模式Factory 在面向对象编程中, 最通常的方法是一个new操作符 ...

  8. mac pro上安装docker

    1.进入一下地址进行下载docker https://download.docker.com/mac/stable/Docker.dmg 进入后进行下载后进行安装 2.将其拖动到Appliaction ...

  9. git配置用户名跟邮箱

    因为我有两个git账号 所以我现在要改变我的默认用户名跟邮件 我就需要去终端设置用户名跟邮箱 具体的命令行就是 设置git的用户名 git config --global user.name &quo ...

  10. 使用Nginx代理Django

    一.准备环境 检查python版本以及pip版本 [root@linux-node01 src]# python --version Python 2.7.5 [root@linux-node01 s ...