码迷,mamicode.com
首页 > 其他好文 > 详细

HW7.1

时间:2016-08-29 19:31:09      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8         double[][] matrix = new double[4][4];
 9         System.out.print("Enter a 4-by-4 matrix row by row: ");
10         for(int i = 0; i < 4; i++)
11             for(int j = 0; j < 4; j++)
12                 matrix[i][j] = input.nextDouble();
13 
14         input.close();
15         System.out.println("Sum of the matrix is " + sumMatrix(matrix));
16     }
17 
18     public static double sumMatrix(double[][] m)
19     {
20         double sum = 0;
21         for(double[] i: m)
22             for(double j: i)
23                 sum += j;
24         return sum;
25     }
26 }

 

HW7.1

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5819126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!