【发布时间】:2014-03-20 10:16:03
【问题描述】:
到目前为止,我有一个汇总列的方法,但这并不是我所需要的。
我需要将每行的总数放在每行的右侧,将每列的总数放在每列的底部。像这样的
1 2 3 4 = 10
3 4 5 6 = 18
4 6 8 10 < - Total
我现在拥有的是每列的总数,但不是列下的总数。
方法
// method to add the sum of columns
public static int[] columnSum(int x[][]){
int temp[] = new int[x[0].length];
for (int i = 0; i < x[0].length; i++){
int sum = 0;
for (int j = 0; j < x.length; j++){
sum += x[j][i];
}
temp[i] = sum;
System.out.println("Index is: " + i + " Sum is: "+sum);
}
return temp;
}
}
【问题讨论】:
标签: java arrays methods multidimensional-array