Assignment #68 Reverse Hi-Lo

Code

    /// Name: Matthew Lorence
    /// Period: 5
    /// Program Name: Reverse HiLo
    /// File Name: ReverseHiLo.java
    
    import java.util.Scanner;
    import java.util.Random;
    
    public class ReverseHiLo
    {
        public static void main (String [] args)
        {
            Scanner keyboard = new Scanner (System.in);
            
            String answer;
            int hi, lo, guess, x;
            lo = 1;
            hi = 1000;
            guess = (lo+hi)/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 (h)igh, too (l)ow, or (c) correct?");
            answer = keyboard.next();
            
            while (!answer.equals("c"))
            { 
                if (answer.equals("h"))
                {
                    hi = guess;
                    guess = (lo+hi)/2;
                    System.out.println("My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c) correct?");
                }
                else if (answer.equals("l"))
                {
                    lo = guess;
                    guess = (lo+hi)/2;
                    System.out.println("My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c) correct?");
                }
                    answer = keyboard.next();
                    System.out.println("Ha!  I am the greatest guesser in the WORLD!");
            }
        }
    }
        
        
        
    

Picture of the output

Assignment 68