【发布时间】:2018-06-17 06:02:27
【问题描述】:
这是我当前的随机二维数组,我需要让每个数组打印在参数中没有重复值。我已经尝试过其他帖子,但没有一篇涉及多维数组,特别是 Math.random。
我排列这个数组值表的方式也有可能吗?稍后我将需要能够测试它们的用户输入。 感谢您的宝贵时间。
public static void main(String[] args) {
System.out.println("B I N G O");
int[][] board = new int[5][5];
for(int i = 0; i < board.length; i++){
for(int j =0; j <board.length; j++){
board[0][j] = (int)(Math.random() *15) +1;
board[1][j] = (int)(Math.random() *15) +16;
board[2][j] = (int)(Math.random() *15) +31;
board[2][2] = 0;
board[3][j] = (int)(Math.random() *15) +46;
board[4][j] = (int)(Math.random() *15) +61;
System.out.printf("%-3s", board[j][i]);
}
System.out.println("");
}
}
}
【问题讨论】:
-
所有尺寸。所以在板[0] [0]。这是 B 列下的第一个数字,到 board[0][4] 是 B 列下的最后一个数字。对于每个打印的字母,依此类推。
标签: java arrays multidimensional-array random