求矩阵中各列数字的和 Exercise08_01
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的更多相关文章
- C++编程求数组中重复的数字
题目:在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度为7的 ...
- Java:求字符串中邻接的数字为一个整体
public static void main(String[] args) { String strNumbers = "0123456789";//用来进行判断数字的 Syst ...
- Maximal Rectangle, 求矩阵中最大矩形,参考上一题
问题描述: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1 ...
- [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 ...
- [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 ...
- 搜索(DFS)---矩阵中的连通分量数目
矩阵中的连通分量数目 200. Number of Islands (Medium) Input: 11000 11000 00100 00011 Output: 3 题目描述: 给定一个矩阵,求 ...
- 剑指offer 数组中的重复数字
问题描述: 在长度为n的数组中,所有的元素都是0到n-1的范围内. 数组中的某些数字是重复的,但不知道有几个重复的数字,也不知道重复了几次,请找出任意重复的数字. 例如,输入长度为7的数组{2,3,1 ...
- c编程:求出4×4矩阵中最大和最小元素值及其所在行下标和列下标,求出两条主对角线元素之和。
//求出4×4矩阵中最大和最小元素值及其所在行下标和列下标,求出两条主对角线元素之和 #include <stdio.h> int main() { int sum=0; int max, ...
- Flex中对表格中某列的值进行数字格式化并求百分比
1.问题背景 一般的,需要对表格中某列的数值进行格式化,对该数值乘以100,并保留两位小数,添加"%" 2.实现实例 <?xml version="1.0" ...
随机推荐
- python设计模式之常用创建模式总结(二)
前言 设计模式的创建模式终极目标是如何使用最少量最少需要修改的代码,传递最少的参数,消耗系统最少的资源创建可用的类的实例对象. 系列文章 python设计模式之单例模式(一) python设计模式之常 ...
- shell 监控磁盘使用率【转】
方案一: disks=(`df |sed 1d | awk '{print $1,$5}'|tr -d %`) len=${#disks[@]} ;i<=$len;i=i+));do ];the ...
- Freemaker 自定义指令和函数
自定义函数和指令都可以在前台或者后台进行指定. 个人理解:指令的作用,主要是进行页面调整之后进行输出:函数的作用,主要是为了进行运算,返回运算结果供前台展示. (一) 自定义指令 使用以下格式调用自定 ...
- 用sar进行CPU利用率的分析
07:40:17 PM CPU %user %nice %system %iowait %steal %idle07:40:19 PM a ...
- 全局应用程序类(Global.asax)
注:该部分参考的园区的“积少成多”的 <ASP.NET MVC中的Global.asax文件> . 1.Global.asax文件介绍 global.asax这个文件包含全局应用程序事件 ...
- 修改vs17中的cordova模板
因为visual studio 2017创建的默认cordova-ios的版本自动编译带有swift语言的插件会出现异常,cordova-ios升级到4.3.1,并且配置build.json能解决问题 ...
- 修改帧大小和socket缓冲区大小(转)
修改帧大小和socket缓冲区大小 MTU (最大传输单元)的缺省值为1500. 通过下面命令将其改为9000(jumbo frame) % ifconfig eth0 mtu 9000 socket ...
- 苹果receipt样例
使用[[NSBundle mainBundle] appStoreReceiptURL]方式获取receipt (iOS7及以上获取receipt的方法) 普通付费 "latest_rece ...
- java版云笔记(八)之关联映射
Mybatis关联映射 通过数据库对象之间的关联关系,反映到到实体对象之间的引用. 加载多个表中的关联数据,封装到我们的实体对象中. 当业务对数据库进行关联查询. 关联 <association ...
- POJ 2431 Expedition (贪心 + 优先队列)
题目链接:http://poj.org/problem?id=2431 题意:一辆卡车要行驶L单位距离,卡车上有P单位的汽油.一共有N个加油站,分别给出加油站距终点距离,及加油站可以加的油量.问卡车能 ...