public class Nan { /** * @param args */ public static void main(String[] args){ Scanner in=new Scanner(System.in); System.out.println("请输入一个3*3矩阵:"); int sum=0; int[][]a=new int[3][3]; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { a[i][j]=in.nextInt(); if(i==j) sum+=a[i][j]; } System.out.print("/n"); } System.out.println("对角线和为"+sum); } }