package test4;
import java.util.Scanner;
public class Test4 {
public static void main(String args[]){
System.out.println("请输入阶数n:");
Scanner reader=new Scanner(System.in);
int n=reader.nextInt();//读入一个n值
int num[][]=new int[n][n];
System.out.println("请输入"+n+"阶方阵");
int sum1=0,sum2=0,sum=0;//存两条对角线的和
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
num[i][j]=reader.nextInt();//将scanner的成员函数nextint()的返回值付给数组num的第i个元素
if(i==j)
sum1=sum1+num[i][j];
if(i+j==n-1)
sum2=sum2+num[i][j];
}
sum=sum1+sum2;
}
System.out.println("对角线的和为"+sum);
}
}