I am trying to create a program that asks the user for a student's name and asks him if the user would like to enter another user (Y/N). This program is repeated until the user enters N after a student is entered.
public static void main(String[] args) {
String student;
char choice;
Scanner s =new Scanner (System.in);
System.out.println("Enter a student");
student = s.nextLine();
System.out.println("Do you want to enter an other student? (Y/N)");
choice = s.next().charAt(0);
switch(choice){
case 'Y':
do{
System.out.println("Enter an other student");
student = s.nextLine();
System.out.println("Do you want to enter an other student? (Y/N)");
choice = s.next().charAt(0);
}while (choice == 'N');
System.out.println("End");
break;
case 'N':
System.out.println("End");
break;
}
}
In the do loop, the program doesn't wait for the user to enter another student. It justs ask the first question and then asks the second without waiting.