【发布时间】:2022-01-10 21:30:03
【问题描述】:
我正在尝试使用二维数组进行座位预订。我遇到了一个问题,其中输出似乎不正确,我不知道如何处理它。我已经尝试了很多次,但仍然没有正确。我只想将星号放在二维表内或行和列内。星号代表座位。
public class BusSeatReservation {
public static void main(String args[]) {
System.out.println("\t\t\t\tBUS SEAT RESERVATION");
char [][] matrix = new char [11][10];
for (int col = 1; col <= 4; col++) {
System.out.print("\t\tCol " + (col) + "\t");
}
System.out.println();
for (int row = 1; row <= 10; row++) {
System.out.println("Row " + (row) + "\t|");
for (int seat = 1; seat <= 4; seat++) {
matrix [row] [seat] = '*';
System.out.print(matrix [row] [seat] + "\t\t");
}
}
System.out.println();
}
}
【问题讨论】:
标签: java arrays multidimensional-array