我是java新手,所以,请用清晰直接的答案回应。我制作了一个 12 x 12 的 0 矩阵。
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
000000000000
我想用1秒的“栅栏”包围中间区域。
111111111111
100000000001
100000000001
100000000001
100000000001
100000000001
100000000001
100000000001
100000000001
100000000001
100000000001
111111111111
我对 Java 很陌生,所以我只知道如何制作 12 x 12 并打印它,但现在如何制作栅栏。我还想知道如何使用循环在 10 x 10 0 网格内随机生成 10 个随机 1 。请帮忙!!!!这是我的代码:
class Main {
public static void main(String[] args){
int[][] gameboard = new int[12][12];// make gameboard
int r_length = gameboard.length;//row length
int c_length = gameboard[0].length;//column length
for (int x = 0; x < gameboard.length; x++) {
for(int y = 0; y < gameboard.length; y++){
gameboard[x][y] = x + y;
gameboard[0][y] = gameboard[1]; //replace row 1 (not working)
gameboard[11][y] = gameboard[1]; //replace row 12 (not working)
gameboard[x][0] = gameboard[1]; //replace column 1 (not working)
gameboard[x][11] = gameboard[1]; //replace column 12 (not working)
}
}
for (int[] a : gameboard) {
for (int x :a) {
System.out.print("0");
}
System.out.println();
}//gameboard printing
}
}
狐的传说
侃侃尔雅
慕的地6264312
相关分类