1
我已经创建了一个长度相同的2维数组,并且它例如随机填充1和0。比较行和列中的元素,在这种情况下是1和0
0100
0010
1110
1111
如何编写程序找到行,列和对角线所有的1和0
这是我到目前为止的代码:
public class Test2dArray {
public static void main(String[] args) {
int row,column;
System.out.print("Enter the lenghth of matrix:");
Scanner input = new Scanner(System.in);
Random rand = new Random();
int mSize = input.nextInt();
int [][] mArray = new int [mSize][mSize];
for (row=0; row < mSize; row++){
for(column=0; column < mSize; column++){
mArray[row][column]=rand.nextInt(2);
System.out.print(mArray[row][column]+ " ");
}
System.out.println();
}
}
}
___'Java'!=='JavaScript' ___ – Rayon