public class Test {
/**
* @param args
*/
public static void main(String[] args) {
int[][] aa = { { 1, 3, 4 }, { 1, 3, 4 }, { 1, 3, 4 } };
System.out.println(sum(aa));
}
public static int sum(int aa[][]) {
if (null == aa || aa.length != aa[0].length)
throw new IllegalArgumentException("æ°ç»ç»æä¸æ»¡è¶³");
int length = aa.length;
int rs = 0;
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
if (i == j || i + j == length-1) {
rs += aa[i][j];
}
}
}
return rs;
}
}
温馨提示:答案为网友推荐,仅供参考