I'm in the inital stage of this program. I'm not getting errors, but when I excute it the program stops at the second iteration giving me this:
StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(Unknown Source)
at HW3.main(HW3.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
>
Thank you
CODE
import java.util.Scanner;
public class HW3
{ public static void main (String[] args)
{
int pass = 1, weight, tot_we = 0;
String input;
char choice;
Scanner keyboard = new Scanner (System.in);
while (pass <= 25 || tot_we <= 1000)
{
for (int i=1; i <= 25; i++)
{
System.out.println("Passenger " + i);
System.out.print("\t Do you have any luggage? ");
input = keyboard.nextLine();
choice = input.charAt(0);
if (choice == 'Y' || choice == 'y')
{
System.out.print("\n\t How much does it weigh? ");
weight = keyboard.nextInt();
}
pass = pass + i;
}
}
System.out.println("This flight will take off with " + pass + " passengers.");
}
}