Reputation: 1
I'm trying to make a method where if the user enters Y, it directs them to the main program. The problem is that when the user enters Y, it prints the introduction again. When the user enters N, it prints "Alright then, goodbye you NERD." and the main program as well.
I've tried using main(); and main(null);
//scanning for input
userInput = scan.next().charAt(0);
//switch for user input
switch (userInput){
case 'Y': main(null);
break;
case 'N': System.out.println("Alright then, goodbye you NERD.");
break;
default: System.out.println("Invalid input, dude. Run this program again and");
System.out.println("either type a capital Y for yes or a capital N for no.");
break;
}//end of switch for user input
Upvotes: -2
Views: 144
Reputation: 781
Use nextLine() method of Scanner, or create a new Scanner in each input request, because scan is using the previous input
userInput = new Scanner(System.in).nextLine().charAt(0);
Upvotes: 0