我目前正在研究一个应该代表竞技场/剧院座位系统的二维阵列。我需要产生 20% 的座位来填补。它是一个 5 x 5 阵列。我需要为要填充的阵列生成 5 个随机座位/行组合。(我正在使用随机数生成器)所有帮助将不胜感激。
到目前为止,这是我的代码:
public class Project5b
{
static int NUMBER_OF_ROWS = 5;
static int NUMBER_OF_SEATS = 5;
static boolean DEBUG = true;
public int RandomInt(int i1, int i2) {
int result = (int) (Math.random() * (i1 - i2 + i1)); // check formula
return result;
}
public static void main(String[] args) {
int seat = 1;
int row = 2;
boolean[][] a_theater;
a_theater = new boolean[NUMBER_OF_ROWS][NUMBER_OF_SEATS];
for (row = 1; row <= NUMBER_OF_ROWS; row++) {
for (seat = 1; seat <= NUMBER_OF_SEATS; seat++) {
a_theater[row - 1][seat - 1] = false;
}
}
if (DEBUG) {
for (row = 1; row <= NUMBER_OF_ROWS; row++) {
for (seat = 1; seat <= NUMBER_OF_SEATS; seat++) {
System.out.println("row" + " " + row + " " + "seat" + " " + seat + " "
+ a_theater[row - 1][seat - 1]);
}
}
}
}
}
谢谢!