import java.util.Scanner;
public class p78_3 {
public static void main(String[] args)
{
int N = 3;
int [][]a=new int[N][N];
int sum=0;
int i,j;
Scanner reader=new Scanner(System.in);
System.out.println("请输入3*3矩阵:");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
a[i][j]=reader.nextInt();
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(i==j)
sum=sum+a[i][j];
System.out.print("三阶方阵主对角线元素的和为:"+sum);
reader.close();
}
}
运行结果: