参考代码:

import java.util.Scanner;


public class Main1138 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int x = sc.nextInt();

int a[][] = new int[x][x];

int sum = 0;

for (int i = 0; i < x; i++) {

for (int j = 0; j < x; j++) {

a[i][j] = sc.nextInt();

if (i == j || i + j == x - 1) {

sum += a[i][j];

}

}

}

System.out.println(sum);

}

}


 

0.0分

2 人评分

  评论区

谢谢
2020-01-09 23:07:20
  • «
  • 1
  • »