title: How to repeatedly change variable count using scanner in java?
body: <p>I want to basically add two symbols, one which is <strong>#</strong> that is <strong>constant</strong> and another one <strong>x</strong> which changes after each user input. To give you an idea, I am creating a word guess game which has multiple options, I got all of them to work except <strong>option 5</strong> which I am stuck on, and which requires this requirement:</p>
  
  <p><em>Before each guess, the program outputs a visual representation of the guess limit and the number of guesses taken.  For example, if the mystery word is 'cat', Player2 starts with 6 guesses, so the program should display a line of 6 # signs (representing the limit as ######).  Each time Player2 makes an incorrect guess, an 'x' is displayed under the #'s.</em> </p>
  
  <p><strong>Note</strong>: the program should print after <strong>each</strong> user input and not after everything is inputted using a scanner.</p>
  
  <p>When player1 inputs a <strong>mysteryphrase</strong> the game <strong>ends after twice the length of the mysteryphrase</strong> </p>
  
  <p>For example: if the mysteryphrase is <strong>Dog</strong> then the game ends after <strong>6</strong> tries or inputs from player2.</p>
  
  <p>Thats why above in the requirement it says <em>"if the mystery word is 'cat', Player2 starts with 6 guesses"</em></p>
  
  <p><strong>The "#" or the "symbol" variable is dependent on twice the length of the mystery phrase, so for example if the mystery word is "dog" then this "#" should appear 6 times</strong></p>
  
  <p><strong>The "x" or "x" variable is dependent on the number of incorrect guesses the player2 makes, for example, if the mystery word is "dog" and player2 guesses lets say "dig" then an "x" should appear after the guess, stating that he/she made an incorrect guess. I just want "x" to appear for incorrect nothing else please</strong>  </p>
  
  <hr>
  
  <p><strong>Last Note:</strong> My program works this way: first player1 will enter the mysteryphrase and then it lists how many letters are in the phrase, then player2 will get the chance to enter <strong>5 letters that tells him/her if the letters are in the mysteryphrase</strong>  Then player2 will guess the word and then a statement will tell him/her right away if the word is correct or incorrect.</p>
  
  <p><strong>So I want the "#" to first appear after 5 letters when player2 is just about to guess the word and not the letters. Then the "#" should appear after each guess following the "x" that states the amount for each incorrect guess only for the word</strong></p>
  
  <p>I have attached an image of my sample input/output: </p>
  
  <p><a href="https://i.stack.imgur.com/qqiIE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qqiIE.png" alt="enter image description here"></a></p>
  
  <p><strong>It may look like the output is after everything is entered but it should be after each input</strong></p>
  
  <p>MY CODE:</p>
  
  <pre><code>else if (option == 5){
                  int counter = 1;
                  int counter2 = 0;
                  boolean go = true;
                  for (int i = 0; i &lt; 5; i++){
                      char letter = keyboard.next().charAt(0);
                      String r = "";
                      boolean found = false;
                      for (int x = 0; x &lt; mysteryphrase.length(); x++){
                          char n = mysteryphrase.charAt(x);
                          if (n == letter){
                              r+=n;
                              found = true;
                          }else{
                              r+="*";
                          }
                      }
                      if (!found){
                          System.out.println(letter+" is not in the word");
                      }else{
                          System.out.println(r);
                          }
                      }
                       while (go){
                          String phrase = keyboard.next();
                          if (!phrase.equals(mysteryphrase)){
                              System.out.println("The mystery word is not "+phrase);
                              counter++;
                              counter2++;
                          }
                          else if (phrase.equals(mysteryphrase)){
                              go = false;
                              counter--;
                              int points = (mysteryphrase.length()*10-counter*5);
                              System.out.println("Correct! The mystery word is "+mysteryphrase);
                              System.out.println("You made "+counter+" incorrect guesses");
                              System.out.println("You get "+points+" points");
                          }
                          if (counter2 == mysteryphrase.length()*2){
                              go = false;
                              System.out.println("\n"+"You made "+counter2+" incorrect guesses");
                              System.out.println("You have no more guesses");
                              System.out.println("You get 0 points");
                              System.out.println("You lost the game");
                      } 
                  }
              }
  </code></pre>