当int
数组不需要计数到10时。我的问题是charat
读数为10,因为它们是两个不同的字符。我如何能够为10例外?例如下面的程序,当您键入5个人时,程序从6-1打印出来,因为1正在从第一个字符10开始读取。当输入6时,charat
正在读取0,因此它会打印6-0。Java将10读为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, 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());
}
}
}
变量'booking'代表什么?这听起来像你正在尝试使用字符串的字符作为数字。也许你应该使用'int []'而不是String。 –
您应该重新考虑您设计代码的方式。我不会使用String作为集合,因为您会遇到各种问题。我还会检查你的“预订”循环工作,因为我可以看到它的一些问题。如果你不知道你想添加多少元素,你可以使用'int []',但是'List'会更简单。 –