该程序在int
数组不需要数到 10 时有效。我的问题是将charat
10 读取为两个不同的字符,它们是。我怎样才能为 10 破例?例如下面的程序,当你输入 5 个人时,程序从 6-1 打印出来,因为 1 是从 10 的第一个字符读取的。当你输入 6 时,charat
是读取 0,所以它打印出来6-0。
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, 1, 1, 0, 0, 0, 0, 0};
for (int i = 0; i < RowA.length; i++) {
if (RowA[i] == 0) {
available = available + (i + 1);
}
if (available.length() > booking.length()) {
booking = available;
System.out.println(booking);
} 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());
}
}
}