该数组打印零,然后才打印数字,并且不计算倾斜
我尝试切换变量并重写为编码循环
import java.util.Scanner;
public class shishistimempire {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s= new Scanner(System.in);
int i;
System.out.println("enter the size of the array");
i=s.nextInt();
int[][] arr= new int[i][i];
for(int j=0;j<arr.length;j++) {
for(int n=0;n<arr.length; n++) {
arr[j][n]= (int) (Math.random()*i+1);
}
for(int y=0;y<arr.length;y++) {
for(int r=0;r<arr.length;r++) {
System.out.print(arr[y][r] + " ");
}
System.out.println();
}
}
int am=0 , ar=0;
for (int o=0; o<arr.length;o++) {
ar= ar+arr[o][o];
}
for(int h=0; h<arr.length;h++) {
am=am+arr[i-1][i-1];
i--;
}
System.out.println("your main slant is" + am);
System.out.println("your second slant is" + ar);
}}
enter the size of the array
4
1 1 4 3
0 0 0 0
0 0 0 0
0 0 0 0
1 1 4 3
2 2 3 2
0 0 0 0
0 0 0 0
1 1 4 3
2 2 3 2
3 1 2 4
0 0 0 0
1 1 4 3
2 2 3 2
3 1 2 4
4 3 2 2
your main slant is7
your second slant is7
千巷猫影
相关分类