求矩阵中各列数字的和 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" ...
随机推荐
- 2017ACM暑期多校联合训练 - Team 3 1003 HDU 6058 Kanade's sum (模拟)
题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest elem ...
- 简单的企业会议管理cms后台模板——后台
链接:http://pan.baidu.com/s/1eRAVAka 密码:olr1
- 用C#实现对MSSqlServer数据库的增删改查---DAL层
说明:本人完成的工作是对传感器--超声波物位计进行硬件集成,上位机通过串口接收传感器数据并将其存到数据库中:在DAL层实现对数据库的增删改查,其中包含两个数据表分别是WaterLevelSet表和Wa ...
- ubuntu 命令配置ip 网关 dns
如果是在虚拟机中使用Ubuntu,先设置好主机的网络,然后配置虚拟机Ubuntu的IP和网关 如果主机操作系统就是Ubuntu,请直接参照下文进行设置 内容如下: 1. 检验是否可以连通,就使用pin ...
- hdu 4347 The Closest M Points (kd树)
版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 4347 题意: 求k维空间中离所给点最近的m个点,并按顺序输出 . 解法: kd树模板题 . 不懂kd树的可以先看看这个 . 不多说, ...
- ansible报错AttributeError: module 'urllib.request' has no attribute 'HTTPSHandler'
报错内容: TASK [activemq : extract activemq tarball] *************************************************** ...
- HTML 禁止显示input默认提示信息
看问题 html代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- [MySQL]You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
执行update语句,出现问题: 问题描述: You are using safe update mode and you tried to update a table without a WHER ...
- hdu 5894(组合数取模)
hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...
- CSS3–2.css3 响应式布局
1.响应式布局 响应式布局是现在很流行的一个设计理念,随着移动互联网的盛行,为解决如今各式各样的浏览器分辨率以及不同移动设备的显示效果,设计师提出了响应式布局的设计方案.所谓的响应式布局,就是一个网站 ...