Its a basic program that is played by 2 people. Player one is suppose to type a number and the second player is suppose to guess the number. However after I test it out, and if I guess too low or too high I get stuck in "Your guess is too low, try again." infinite loop and I have no idea what is wrong.
import java.io.*; class GuessingGame { public static void main (String[] args) throws IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); String firstPlayer, secondPlayer; int firstInput, secondInput; int guessCount = 0; System.out.println("Player One, please input any integer lower than 1000"); firstPlayer = stdin.readLine (); firstInput = Integer.parseInt (firstPlayer); System.out.println("Player Two, please guess the number"); secondPlayer = stdin.readLine (); secondInput = Integer.parseInt (secondPlayer); { while (secondInput < firstInput) { System.out.println("Your guess was too low, try again."); guessCount ++; } } { while (secondInput > firstInput) { System.out.println("Your guess was too high, try again."); guessCount ++; } } if (secondInput == firstInput) { System.out.println("You have guessed the correct number, the correct number was: " + firstInput); guessCount ++; System.out.println("Your total guess was: "+ guessCount); } } }
Please help!