创建一个代码,用户可以在其中输入他们想要的座位数量,即行。当我只为一行执行程序时,它运行良好。我不知道为什么它现在不起作用。喜欢0的想法。如果有人可以帮助解决这个问题,我将不胜感激。
只有一行的代码在第一行之后。
注意:如果我之前不清楚,当程序运行时,它只会询问座位数量,其他一切都只是崩溃/不起作用。我真的不知道如何解决这个问题。
Java应用程序1
package javaapplication1;
import java.util.*;
/**
*
* @author ziyue
*/
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)throws Exception {
Scanner input = new Scanner(System.in);
System.out.println("Enter the amount of people in your group, up to 6");
int num = input.nextInt();
System.out.println("Please enter the desiered row, A-E. Enter capitals.");
String ROW = input.nextLine();
int[] r = {};
int[] RowA = {0,0,1,1,1,0,0,0,0,0};
int[] RowB = {0,0,1,1,1,0,0,0,0,0};
int[] RowC = {0,0,1,1,1,0,0,0,0,0};
int[] RowD = {0,0,1,1,1,0,0,0,0,0};
int[] RowE = {0,0,1,1,1,0,0,0,0,0};
int highest = num - 1;
String available = "";
String booking = " ";
if ("A".equals(ROW)) {
r = RowA;
}
if ("B".equals(ROW)) {
r = RowB;
}
if ("C".equals(ROW)) {
r = RowC;
}
if ("D".equals(ROW)) {
r = RowD;
}
if ("E".equals(ROW)) {
r = RowE;
}
for (int i = 0; i < r.length; i++) {
if (r[i] == 0) {
available = available + (i + 1);
}
if (available.length() > booking.length()) {
booking = available;
}else if (r[i] == 1) {
available = "";
}
}
if (num <= booking.length()) {
char low = booking.charAt(0);
char high = booking.charAt(highest);
System.out.println("There are seats one the row " + ROW + "from " + low + " - " + high + ".");
} else {
System.out.println("The desired seat amount is not available. The maximum amount on Row is " + booking.length());
}
}
}
Java应用程序2
package javaapplication2;
import java.util.*;
public class JavaApplication2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the amount of people in your group, up to 6");
int num = input.nextInt();
if (num > 6) {
System.out.println("You have exceeded the maximum amount of people allowed.");
}
int highest = num - 1;
String available = "";
String booking = " ";
int[] RowA = {0, 0, 1, 0, 0, 0, 1, 0, 0, 1};
for (int i = 0; i < RowA.length; i++) {
if (RowA[i] == 0) {
available = available + (i + 1);
}
if (available.length() > booking.length()) {
booking = available;
} else if (RowA[i] == 1) {
available = "";
}
}
if (num <= booking.length()) {
char low = booking.charAt(0);
char high = booking.charAt(highest);
System.out.println("There are seats from " + low + " - " + high + ".");
} else {
System.out.println("The desired seat amount is not available. The maximum amount on Row is " + booking.length());
}
}
}