Java数组不';行不通

Java数组不';行不通,java,arrays,Java,Arrays,创建一个代码,用户在其中输入他们想要的座位数量,即行。当我只做了一行程序时,它工作得非常好。我不知道为什么现在不行。 我喜欢你的主意。如果有人能帮我解决这个问题,我将不胜感激 只有一行的代码在第一行之后 注意:如果我之前不清楚,当程序运行时,它只会询问座位数量,而其他一切都会崩溃/不起作用。我真的不知道如何解决这个问题 JavaApplication1 package javaapplication1; import java.util.*; /** * * @author ziyue

创建一个代码,用户在其中输入他们想要的座位数量,即行。当我只做了一行程序时,它工作得非常好。我不知道为什么现在不行。 我喜欢你的主意。如果有人能帮我解决这个问题,我将不胜感激

只有一行的代码在第一行之后

注意:如果我之前不清楚,当程序运行时,它只会询问座位数量,而其他一切都会崩溃/不起作用。我真的不知道如何解决这个问题

JavaApplication1

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());
        }
    }

}
PackageJavaApplication1;
导入java.util.*;
/**
*
*@作者紫月
*/
公共类JavaApplication1{
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args)引发异常{
扫描仪输入=新扫描仪(System.in);
System.out.println(“输入组中的人数,最多6人”);
int num=input.nextInt();
System.out.println(“请输入设计行,A-E.输入大写字母”);
String ROW=input.nextLine();
int[]r={};
int[]RowA={0,0,1,1,1,0,0,0,0};
int[]RowB={0,0,1,1,1,0,0,0,0};
int[]RowC={0,0,1,1,1,0,0,0,0};
int[]RowD={0,0,1,1,1,0,0,0,0};
int[]RowE={0,0,1,1,1,0,0,0,0};
int最高=num-1;
字符串可用=”;
字符串=”;
如果(“A”。等于(行)){
r=罗瓦;
}
如果(“B”。等于(行)){
r=行B;
}         
如果(“C”。等于(行)){
r=RowC;
}         
如果(“D”。等于(行)){
r=RowD;
}         
如果(“E”。等于(行)){
r=罗;
}         
对于(int i=0;ibooking.length()){
预订=可用;
}else如果(r[i]==1){
可用=”;
}
}                           
如果(数字6){
System.out.println(“您已超过允许的最大人数”);
}
int最高=num-1;
字符串可用=”;
字符串=”;
int[]RowA={0,0,1,0,0,0,1,0,0,1};
for(int i=0;ibooking.length()){
预订=可用;
}else if(RowA[i]==1){
可用=”;
}
}

如果(num问题是您的输入不正确。您假设数字和字母在不同的行上,但这不是您的输入所做的

System.out.println("Enter the amount of people in your group, up to 6");
int num = input.nextInt();
// discard the rest of the first line and 
// expect the next input to be on the next line.
input.nextLine(); 

System.out.println("Please enter the desiered row, A-E. Enter capitals.");
String ROW = input.nextLine();
如果不放弃第一行的结尾,该行将包含您在第一行数字后键入的内容


如果您在调试器中逐步查看代码,您会发现该行不是您所期望的,从而节省了您分配的时间。

sooo…到底是什么问题?为什么不能有一个数组?您已经给出了很多代码,但很少指出它到底出了什么问题。请尽量减少所需的内容,以显示g是什么错了,你可能会发现你自己找到了答案。太多的代码帮不了你。你需要给我们一个指南和一些相关的代码部分,而不是整个应用程序。你是说Java的数组不工作,你是说你不能使用Java的数组吗?;)
System.out.println("Enter the amount of people in your group, up to 6");
int num = input.nextInt();
// discard the rest of the first line and 
// expect the next input to be on the next line.
input.nextLine(); 

System.out.println("Please enter the desiered row, A-E. Enter capitals.");
String ROW = input.nextLine();