求一个3*3矩阵对角线元素之和
public static void main(String[] args) { int[][] a={{1,2,3,},{4,5,6},{7,8,9}}; System.out.println(a.length); int sum=0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { if(i==j || i+j==a.length-1){ sum+=a[i][j]; } System.out.print(" "+a[i][j]); } System.out.println(); } System.out.println(sum); }