title: How to loop a certain area of code after a wrong user input? (Java)
body: <p>I have been working on a small Rock Paper Scissors game with Java, where the win or lose condition is based on whether the computer or the player wins five games. I am not sure how to get the program to loop at the user input should there be a wrong input.</p>
  
  <p>Here is the code where I'm having this trouble</p>
  
  <p>The section that I'm trying to loop is the portion with "else if (determination.equals("Y")) {"</p>
  
  <pre><code>import java.util.*;
  
  public class Rock_Paper_Scissors {
  
    public static void main(String arg[]) {
      boolean loopGameStart = true;
  
      while (loopGameStart) {
        System.out.println("Welcome to Rock Paper Scissors, a game programmed "
                         + "by Daniel Park. Would you like to start? (Y/N)");
        Scanner userInput = new Scanner(System.in);
        String determination = userInput.next();
  
        if (determination.equals("N")) {
          System.out.println("Please, do reconsider...");
          loopGameStart = true;
        } else if (determination.equals("Y")) {
          Random rand = new Random();
          int n = rand.nextInt(3) + 1;
          // 1 = Rock, 2 = Paper, 3= Scissor
          int humanWinCount = humanWinCount();
          int computerWinCount = computerWinCount();
          System.out.println("Choose 0, 1, or 2 (Rock/Paper/Scissor)");
          Scanner userRPS = new Scanner(System.in);
          int choiceRPS = userRPS.nextInt();
          while ((humanWinCount &lt; 5) &amp;&amp; (computerWinCount &lt; 5)) {
            if (choiceRPS == 0) {
              if (n == 1) {
                System.out.println("TIE!!");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else if (n == 2) {
                System.out.println("LOSS!!");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                computerWinCount = computerWinCount + 1;
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else if (n == 3) {
                System.out.println("WIN!!");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                humanWinCount = humanWinCount + 1;
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else {
                System.out.println("I do not understand... Try Again.");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              }
            } else if (choiceRPS == 1) {
              if (n == 1) {
                System.out.println("WIN!!");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                humanWinCount = humanWinCount + 1;
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else if (n == 2) {
                System.out.println("TIE!!");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else if (n == 3) {
                System.out.println("LOSS!!");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                computerWinCount = computerWinCount + 1;
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else {
                System.out.println("I do not understand... Try again.");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              }
            } else if (choiceRPS == 2) {
              if (n == 1) {
                System.out.println("LOSS");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                computerWinCount = computerWinCount + 1;
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else if (n == 2) {
                System.out.println("WIN!!");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                humanWinCount = humanWinCount + 1;
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else if (n == 3) {
                System.out.println("TIE!!");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              } else {
                System.out.println("I do not understand... Try again.");
                System.out.println("Choose 0, 1, or 2 again (Rock/Paper/Scissor)");
                System.out.println("Computer: " + computerWinCount + " rounds won");
                System.out.println("You: " + humanWinCount + " rounds won");
                choiceRPS = userRPS.nextInt();
              }
            }
          }
  
          if (humanWinCount == 5) {
            System.out.println("Congratulations, you win!!");
            System.out.println("Computer: " + computerWinCount + " rounds won");
            System.out.println("You: " + humanWinCount + " rounds won");
            System.out.println("Would you like to try again? (Y/N)");
            Scanner continueOrNot = new Scanner(System.in);
            String contOrNot = continueOrNot.next();
            if (contOrNot.equals("Y")) {
              loopGameStart = true;
            } else if (contOrNot.equals("N")) {
              System.out.println("Okay, goodbye!!");
              loopGameStart = false;
            }
          }
  
          if (computerWinCount == 5) {
            System.out.println("Boohoo, you lost!!");
            System.out.println("Computer: " + computerWinCount + " rounds won");
            System.out.println("You: " + humanWinCount + " rounds won");
            System.out.println("Would you like to try again? (Y/N)");
            Scanner continueOrNot = new Scanner(System.in);
            String contOrNot = continueOrNot.next();
            if (contOrNot.equals("Y")) {
              loopGameStart = true;
            } else if (contOrNot.equals("N")) {
              System.out.println("Okay, goodbye!!");
              loopGameStart = false;
            }
          }
        } else {
          System.out.println("I do not understand, please try again!");
        }
      }
    }
  
    public static int humanWinCount() {
        int x = 0;
        return x;
    }
  
    public static int computerWinCount() {
        int c = 0;
        return c;
    }
  }
  </code></pre>