import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double[][] a=new double[3][3]; //数组大小
int sum1=0,sum2=0;
for(int x=0;x<=2;x++){
for(int y=0;y<=2;y++){
a[x][y]=scanner.nextDouble();//输入3乘3矩阵
}
}
for(int i=0;i<=2;i++){
for(int j=0;j<=2;j++){
if(i==j){ //判断主对角线
sum1+=a[i][j];
}
if(i+j==2){ //判断次对角线
sum2+=a[i][j];
}
}
}
System.out.println(sum1+" "+sum2);
}
}
思路:(1)用二维数组a[x][y]来存储,(2)主对角线特征x==y,次对角线特征x+y==2;