0

I have created an array list with size 10. It was just fine with the first object in the array. But, then I figured out that user's input in the second object in the array got skipped. (It won't ask user to enter their name starting from the second object in the array)

    for (int i = 0; i < 10; i++)
       {
        array[i] = new Homestay();
        
        System.out.println("\nEnter Customer Name");
        nama = keyboard.nextLine();
        /*prob: the second array won't ask user their name.
        if i write keyboard.nextLine(); again, it will ask 
        user's name(input), but it won't display the user's name(output).*/

Output:

The first object in the array list

Enter Customer Name /it can ask the user's name and it can also display the output/

Jungkook

The second object in the array

Enter Customer Name //this line got skipped

Enter Customer No

  • That is not a [mre], but your problem is probably [Scanner is skipping nextLine() after using next() or nextFoo()](https://stackoverflow.com/q/13102045/3890632) – khelwood Jan 24 '21 at 17:15
  • hey khelwood thank you so much! –  Jan 25 '21 at 11:33

0 Answers0