I'm new to programing and I'm having a problem with my scanner class. This code is in a loop and when the loop comes around the second, third whatever time I have it set to it skips the first title input. I need help please why is it skipping my title scanner input in the beginning?
System.out.println("Title:");
list[i].title=keyboard.nextLine();
System.out.println("Author:");
list[i].author=keyboard.nextLine();
System.out.println("Album:");
list[i].album=keyboard.nextLine();
System.out.println("Filename:");
list[i].filename=keyboard.nextLine();
It is likely that, in the code you haven't shown us, there exists a call to one of Scanner input methods that does not consume a newline method. nextLine for example. In this instance the newline character will be passed from the end of the loop to the subsequent nextLine statement. This now will not block having received input. The solution is to ensure the newline is consumed at the end of each iteration
// list[i].id = keyboard.nextInt();
list[i].id = Integer.parseInt(keyboard.nextLine());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With