求一个n阶方阵对角线元素之和
import java.util.Scanner;
public class DuiJiao{
public static void main(String args[]){
int n;
int sum=0;
Scanner reader=new Scanner(System.in);
n=reader.nextInt();
int[][] a=new int[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
a[i][j]=reader.nextInt();
for(int i=0;i<n;i++)
sum+=a[i][i];
System.out.println("对角线之和为:"+sum);
}
}