Getting the Code to Restart After Invalid Entry (Java)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Getting the Code to Restart After Invalid Entry (Java)



I'm working on this block of code:


while (!userCorrect)
Scanner input = new Scanner(System.in);
System.out.print("Guessing (round " + roundNumber1++ + "): Choosing your letter from a-z: ");
String letter = input.nextLine();
if (letter.length () > 1)
System.out.println("You should not enter more than 1 character");



System.out.println("end of (round " + roundNumber2++ + ")");

}



What I'm trying to do is after the user inputs more than 1 character, the code goes back to:



System.out.print("Guessing (round " + roundNumber1++ + "): Choosing your letter from a-z: ");



Until only 1 character is selected and then moves onto round 2.



Ex. assuming it's round 1 and the user inputs az. It'll throw my error saying that you should not enter more than 1 character and then it'll go back to:



Guessing(round 1): Choosing your character from a-z:



Any ideas? I got it to work but it's skipping to the next round and I want it to stay on the same round until a valid input. I've been searching for hours and can't get it to work.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS