当我尝试将字符串放入控制台时,循环不会将我的字符串添加到数组中,而是直接出现错误。我在这里想念什么?

public static void main(String[]args)
  {
      System.out.println("Trucks running today (min 2):  ");
      Scanner trucks = new Scanner(System.in);

      int userTrucks = trucks.nextInt();
      int [] x = truckNumberArray(userTrucks);
        if(x == null)
            {
                System.out.print("Error: must be at least two trucks.");
                System.exit(0);
            }
    Scanner size = new Scanner(System.in);
    String [] largeSmall = new String[x.length];
    for(int t = 1; t<x.length;t++)
         {

            System.out.println("Truck is large or small (large max = 100, small max = 10)?  ");
            largeSmall[t] = size.nextLine();
            if (largeSmall.equals("small"))
                {
                    System.out.print(" ");
                }
            else if (largeSmall.equals("large"))
                {
                    System.out.print(" ");
                }
            else
                {
                        System.out.println("error");
                        System.exit(0);
                }

         }
   }
}

最佳答案

注意:if (largeSmall.equals(...

修改:if (largeSmall[t].equals(...

10-06 07:10
查看更多