im making a program that uses an array to store a guestlist. One of the options in the menu is to add a guest, but when i try this option it doesnt wait for user to make its name input and immedietly jumps to the next statement wich asks for the age. Please help!
else if(choice==3){
System.out.print("Name of guest: ");
String name = input.nextLine();
System.out.print("Age of guest: ");
String age = input.nextLine();
addGuest(name,age);
}
output: Name of guest: Age of guest:
Update: I managed to solve the problem by adding input.nextLine(); after the first print. I dont really understand the explanation given here Scanner is skipping nextLine() after using next() or nextFoo()? but it worked.