日期:2014-05-20  浏览次数:20681 次

新手求解 关于数组问题
例如:一个二维数组 int [] score={{1,2,3,4,5,6,7,8,9},{11,22,33,44,55,66,77,88,99},{22,33,44,55,66,77,88,99},{100,200,300,400,500,600,700,800}};
怎么求他们的和? 用for循环来写出代码.
  高手们看到这么简单的问题是不是笑了?因为我也笑了,笑一笑十年少,愁一愁白了头。哈哈
  结贴100%!

------解决方案--------------------
Java code

int [][] score={{1,2,3,4,5,6,7,8,9},{11,22,33,44,55,66,77,88,99},{22,33,44,55,66,77,88,99},{100,200,300,400,500,600,700,800}};
        int sum = 0;
        for(int i = 0;i < score.length;i++){
            for(int j = 0;j < score[i].length;j++){
                sum += score[i][j];
            }
        }
        System.out.println(sum);