Assignment #68 Reverse Hi-Lo

Code

    /// Name: Koosha Kimelman
    /// Period: 7
    /// Program Name: Reverse Hi-Lo
    /// File Name: ReverseHighLow.java
    /// Date Completed: 11/13/15
    
    import java.util.Scanner;
    
    public class ReverseHighLow {
    
        public static void main(String[] args) {
        
            Scanner keyboard = new Scanner(System.in);
            
            int guess, high, low;
            String answer;
            high = 1000;
            low = 1;
            guess = ((high+low)/2);
            
            System.out.println("Think of a number from 1 to 1000. I'll try to guess it.");
            System.out.println("My guess is " + guess + ". Am I too \"high\", too \"low\", or \"correct\"?");
            System.out.print("> ");
            answer = keyboard.next();
            
            while (!answer.equals("correct")) {
                if (answer.equals("high")) {
                    high = guess;
                    guess = ((high+low)/2);
                }
                else if (answer.equals("low")) {
                    low = guess;
                    guess = ((high+low)/2);
                }
                System.out.println("My guess is " + guess + ". Am I too \"high\", too \"low\", or \"correct\"?");
                System.out.print("> ");
                answer = keyboard.next();
                if (answer.equals("low") && guess == 999)
                    guess++;     // This part here is because when it got to 999 after constantly inputting "low", it would never make it to 1000. It would always guess 999, so if the number the person chose was 1000, it would never make it without this.
            }
            
            System.out.println("\nI knew I'd get it eventually.");
        }
    }
    

Picture of the output

Assignment 68