Hey,
Well I passed my last assignment that I had help from here on with a fairly high grade. Now that I've run into another little problem I decided to come back and get some help again. =) The problem this time is that when I run my program in the console it freezes after Player 2 enters a number; I know this has something to do with my 'while' loop but I can't seem to see any problem with the way it's set up.
import java.io.*; class Assignment7Question1 { public static void main (String[] args) throws IOException { int intFirstInt = 0, intGuesses = 0, intGuessedNumber = 0; //Creates the three variables that will be used in this program. InputStreamReader inStream = new InputStreamReader (System.in); BufferedReader userInput = new BufferedReader (inStream); String inputData; //Creates one string variable System.out.println ("Player 1:"); //Prints the sentence to the cmd. System.out.println ("Please input a positive number that is less than 1000:"); //Prints the sentence to the cmd. inputData = userInput.readLine ( ); //Places input into inputData string variable. intFirstInt = Integer.parseInt(inputData); //Sets the value saved into inputData to the intFirstInt variable. System.out.println ("Player 2:"); //Prints the sentence to the cmd. System.out.println ("Please enter the number that you believe Player 1 has entered."); //Prints the sentence to the cmd. inputData = userInput.readLine(); //Places input into inputData string variable. intGuessedNumber = Integer.parseInt(inputData); //Sets the value saved into inputData to the intGuessedNumber variable. while (intGuessedNumber > intFirstInt | intGuessedNumber < intFirstInt); { intGuesses = (intGuesses + 1); //Counts the number of guesses that Player 2 takes to get the correct number. if (intGuessedNumber > intFirstInt) System.out.println ("Your guess is too low! Please try again."); //Prints the sentence to the cmd. else if (intGuessedNumber < intFirstInt) { System.out.println ("Your guess is too high! Please try again."); //Prints the sentence to the cmd. } inputData = userInput.readLine(); //Places input into inputData string variable. intGuessedNumber = Integer.parseInt(inputData); //Sets the value saved into inputData to the intGuessedNumber variable. } if (intGuessedNumber == intFirstInt) { System.out.println ("Congratulations, you guessed correctly!"); System.out.println ("It took you "+intGuesses+" guesses to determine the number."); } } }
Sorry for some of the indentation being off, when I CnP the code from Notepad++ to here it messes it up.