注意事项:注意Java数组输入格式为:类型[][] 变量名 = new 类型[][]
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x=0,y=0;//和
int[][] a = new int[3][3];
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
a[i][j]=input.nextInt();
if(i==j) {
x = x + a[i][j];
}
if(i==2-j) {
y = y + a[i][j];
}
}
}
System.out.println(x + " " + y);
}
}
0.0分
0 人评分