我正在打印 0-99 的值和食物数组中的随机字符串。我似乎无法正确地将它们输出到表格中。
String foods[] = {"Bread", "Pizza", "Cheese"};
for (int x = 0; x<=99; x++) {
for (int i = 0; i<4; i++) {
int random = (int) (Math.random() * 3);
System.out.print(x + " - " + foods[random] + "\t\t");
}
System.out.println();
}
实际输出:
0 - Pizza 0 - Bread 0 - Cheese 0 - Bread
1 - Bread 1 - Pizza 1 - Bread 1 - Pizza
.... until 99
预期输出:
0 - Pizza 1 - Bread 2 - Cheese 3 - Bread
4 - Bread 5 - Pizza 6 - Bread 7 - Pizza
.... until 99