寫了一個程序來驗證連續相鄰的座位數量。座位是預定的或可用的,由0或1表示。該程序大部分適用。如果所需的一排座位可用,它將輸出一條消息說明。什麼是錯誤的是,當所需的席位數量不可用或超過6.我如何解決這個問題?Array does not work read can not explain too too too explain
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();
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 = "";
}
}
char low = booking.charAt(0);
char high = booking.charAt(highest);
if (num <= booking.length()) {
System.out.println("There are seats from " + low + " - " + high + ".");
System.out.println(booking);
}
else {
System.out.println("Sorry, the desired seat amount is not available. The maximum amount on Row is " + booking.length());
}
}
}
什麼標題的問題! –
根據您的理想座位數量不可用,什麼*錯誤? – Patrick
聽起來像給我作業。 – Damien