巴士座位预订:
Col1 Col2 Col3 Col4 Row 0 | * * * * Row 1 | * * * * Row 2 | * * * * Row 3 | * * * * Row 4 | * * * * Row 5 | * * * * Row 6 | * * * * Row 7 | * * * * Row 8 | * * * * Row 9 | * * * *
import java.util.*;
public class SeatReservation{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
char[][] upuan = new char[10][4];
for (int a = 0; a < upuan.length; a++){
for(int b = 0; b < upuan[a].length; b++){
upuan[a][b] = '*';
}
}
while (true){
System.out.println("Bus Seat Reservation:");
System.out.println("\t\tCol1\tCol2\tCol3\tCol4");
for (int a = 0; a < upuan.length; a++){
System.out.println("Row " + a + "\t|");
for (int b = 0; b < upuan[a].length; b++){
System.out.print(upuan[a][b] + "\t\t");
}
}
System.out.println();
System.out.print("Enter row and colum to reserve separated by space (Enter a negative number to exit): ");
String input = sc.nextLine();
if(input.contains("-")){
System.out.println("Program Exit");
break;
}
int row = Character.getNumericValue(input.charAt(0));
int column = Character.getNumericValue(input.charAt(2));
upuan[row][column] = 'X';
}
}
}
答案 0 :(得分:0)
打印第一个“行...”时,您使用的是println()
。这将打印行,然后引入换行符。
尝试对行使用print()
,然后在for循环后使用println()
。