Assignment #68 Reverse Hi-Lo

Code

    /// Name: John Huh
    /// Period: 6
    /// Program Name: Reverse Hi-Lo
    /// File Name: ReverseHiLo.java
    /// Date Finished: 12/17/2015
    
        import java.util.Scanner;
        
        public class ReverseHiLo
        {
            public static void main( String[] args )
            {
                Scanner keyboard = new Scanner(System.in);
                int hi, lo, guess;
                String initial;
                
                lo = 1;
                hi = 1000;
                guess = ( lo + hi ) / 2;
                
                System.out.println();
                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)orrect?" );
                System.out.print( "> " );
                initial = keyboard.next();
                
                while ( !initial.equals("c") )
                {
                    if ( initial.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)orrect?" );
                        System.out.print( "> " );
                        initial = keyboard.next();
                    }
                    
                    else if ( initial.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)orrect?" );
                        System.out.print( "> " );
                        initial = keyboard.next();
                    }
                }
                
                System.out.println();
                System.out.println( "Ha!  I am the greatest guesser in the WORLD!" );
            }
        }
    

Picture of the output

Assignment 1