-2
我需要維數組的總和.......... 如何添加二維數組的總和,我做到這一點,但當我嘗試添加標記[i] [j]這是沒有得到可能我..如何添加二維數組,這個程序
import java.util.Scanner;
public class TwoDimArray {
static int i, j;
public static void main(String[ ] args) {
int [ ][ ] marks = new int [4][4];
Scanner sc = new Scanner(System.in);
for (i = 1; i < marks.length ; i ++) {
System.out.println ("Enter marks of student "+i);
for (j = 1; j < marks[i].length ; j++) {
System.out.println ("Subject "+j);
marks [i][j] = sc.nextInt();
}
}
for (i = 1; i < marks.length ; i++) {
for (j = 1; j < marks[i].length ; j++){
System.out.print (marks[i][j]+" ");
}
}
}
}
output:
Enter marks of student 1
Subject 1
45
Subject 2
48
Subject 3
47
Enter marks of student 2
Subject 1
52
Subject 2
56
Subject 3
54
Enter marks of student 3
Subject 1
65
Subject 2
66
Subject 3
75
45 48 47 52 56 54 65 66 75
*/
我想總結標記[i] [j],我怎麼能添加 學科的總和,請解釋如何科目總和...
你有一個'INT sum',並且添加了標記它。 – Teepeemm 2014-09-24 12:22:33
首先,數組以索引0開始,而不是1開始。 – Magnilex 2014-09-24 12:23:11