Java Wrong User Input Loop until correct
<p>I have a problem validating the program. I have tried using, While/Switch but it is all the same. The issue is when a user enters the wrong input for example 5, it shows the error and then it lets them type it in again, but if they type in the wrong number again, the program does not validate. I can definitely copy the code again and again within it, but there should be an easier way.</p>
<p>I hope you understand what I am trying to achieve.</p>
<p>How could I make it so it is a continues loop?</p>
<pre><code>// Choosing the right room
public static int rooms () {
    int room;

    // Creating a new keyboard input
    Scanner scanner = new Scanner(System.in);
    // Displaying a message on the screen
    System.out.println(&quot;What room are you in? &quot;);
    // Input
    room = scanner.nextInt();

    if (room==1) {
        roomOne();
    } else if (room==2) {
        roomTwo();
    } else if (room==3) {
        roomThree();
    } else if (room==4) {
        roomFour();
    } else {
        System.out.println(&quot;Wrong room number, please enter the room number.&quot;);
        room = scanner.nextInt();
    }

    //System.out.println(&quot;Sorry but you entered the wrong room number &quot; + room + &quot; Enter the correct room number 1-4 &quot;);    

    return room;
} // End Rooms
</code></pre>