package erase; import java.util.Scanner; public class 二维数组求对角线元素和 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int n=in.nextInt(); if(n%2==0)n++; int sum = 0; int m[][]=new int[n][n]; for(int i=0;i<n;i++) {//行 for(int j=0;j<n;j++) {//列 if(i==j || j==n-i || i==n-j) { m[i][j]=j; sum+=m[i][j]; } } } System.out.print("二维数组对角之和为"+sum); } }