Java 如何显示飞机座位表?
这是我的代码:Java 如何显示飞机座位表?,java,arrays,eclipse,for-loop,Java,Arrays,Eclipse,For Loop,这是我的代码: import java.util.Scanner; public class AirlineReservation { public static void main(String[]args) { System.out.println("Enter n:"); Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); in
import java.util.Scanner;
public class AirlineReservation {
public static void main(String[]args) {
System.out.println("Enter n:");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] airplane = new int[n][4];
for(int i = 1; i < 4; i++) {
System.out.printf("%3d\t", i);
}
for(int j = 0; j <= n; j++) {
System.out.println((j) + " -" + " -" + " -" + " -");
}
}
}
只需控制你的鞋垫:
public static void main(String[]args) {
System.out.println("Enter n:");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] airplane = new int[n][4];
for(int i = 1; i <= 4; i++) {
System.out.printf("\t%d\t", i);
}
System.out.println("");
for(int j = 1; j <= n; j++) {
System.out.printf("%d", j);
for (int k = 1; k <= 4; k++) {
System.out.print("\t-\t");
}
System.out.println("");
}
}
publicstaticvoidmain(字符串[]args){
System.out.println(“输入n:”);
扫描仪=新的扫描仪(System.in);
int n=scanner.nextInt();
int[][]飞机=新的int[n][4];
对于(inti=1;i,代码中有几个错误
第一个for循环应该从1开始到4结束(都包括在内),所以我添加了一个=
for (int i = 1; i <= 4; i++) {
System.out.printf("%3d\t", i);
}
for(int i=1;i将您的代码改写为:
import java.util.Scanner;
public class AirlineReservation {
public static void main(String[]args) {
System.out.println("Enter n:");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] airplane = new int[n][4];
for(int i = 1; i <= 4; i++) {//Change here.
System.out.printf("%3d\t", i);
}
System.out.println();//Change here.
for(int j = 1; j <= n; j++) {
System.out.println((j) + " -" + " -" + " -" + " -");//change Here.
}
}
}
import java.util.Scanner;
公营航空公司{
公共静态void main(字符串[]args){
System.out.println(“输入n:”);
扫描仪=新的扫描仪(System.in);
int n=scanner.nextInt();
int[][]飞机=新的int[n][4];
对于(int i=1;i好的,我已经修复了数组在错误行上的问题,但是如何输入“-”在每个开放点?稍后我希望用户选择一个座位并将其x'd。您是否可以显示您的示例输出和您期望的输出,我用输出编辑了原始问题。您是否可以改写您的问题,因为您显示的输出对于开放座位为“-”,但您已声明为“和”-“在每个有开放座位的区域标记(它没有)”这样更好吗?否则请给我一个编辑建议
for (int row = 1; row <= n; row++) {
System.out.print(j); // Print the number of row
for (int seat = 1; seat <= 4; seat++) {
System.out.print(" -"); // Print each seat
}
System.out.println(""); // Go to the next line
}
for (int row = 1; row <= n; row++) {
System.out.print(j); // Print the number of row
for (int seat = 1; seat <= 4; seat++) {
System.out.print(" "); // Print separator
if (airplane[row - 1][seat - 1] == 0) {
System.out.print("-");
} else {
System.out.print("X");
}
}
System.out.println(""); // Go to the next line
}
import java.util.Scanner;
public class AirlineReservation {
public static void main(String[]args) {
System.out.println("Enter n:");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] airplane = new int[n][4];
for(int i = 1; i <= 4; i++) {//Change here.
System.out.printf("%3d\t", i);
}
System.out.println();//Change here.
for(int j = 1; j <= n; j++) {
System.out.println((j) + " -" + " -" + " -" + " -");//change Here.
}
}
}