java - 如何调整行并将其移动到右侧
问题描述
巴士座位预订:
Col1 Col2 Col3 Col4 第 0 行 | * * * * 第 1 行 | * * * * 第 2 行 | * * * * 第 3 行 | * * * * 第 4 行 | * * * * 第 5 行 | * * * * 第 6 行 | * * * * 第 7 行 | * * * * 第 8 行 | * * * * 第 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';
}
}
}
解决方案
当您打印第一个“行...”时,您正在使用println()
. 这将打印该行,然后引入换行符。
尝试使用print()
for 行,然后println()
在 for 循环之后使用 a。
推荐阅读
- javascript - 过滤并将结果映射到新数组中
- javascript - AngularJs - 删除我在 ng-repeat 中点击的卡片
- c# - .NET 核心 2.1。通过 HTTPS 从一个 Docker 容器发布到另一个容器的问题
- arrays - 创建 SQL 查询和 Power-Shell 比较 arrayArray
- swift - Swift - 通过 IBAction 将 UIImageView 作为 PNG 文件保存到图库
- r - 在 ggplot 中使用 geom_violin 出现对数刻度图的问题
- mysql - 添加一个月至今的 TIMESTAMP
- spring-cloud-dataflow - Spring Cloud 数据流服务器内存管理
- visual-studio-code - PyTorch DataLoader 的 VSCode 错误?
- shopify - Shopify 应用程序开发需要标题上的按钮