Assignment #68

Code

    /// Name: Jonathan Stine
    /// Period: 5
    /// Program Name: Reverse Hi-Lo
    /// File Name: Reverse.java
    /// Date Finished: 1/19/16
    
    import java.util.Scanner;
    
    public class Reverse {
        
        public static void main( String[] args ) {
            
            Scanner keyboard = new Scanner(System.in);
            
            String response = "a";
            
            System.out.println( "Think of a number from 1 to 1000. I WILL GUESS IT!!!" );
            int lo = 1;
            int hi = 1000;
            
            while ( !response.equals("c") ) {
                
               
                int guess = ( lo + hi ) / 2;
                
                System.out.println( "My guess is " + guess + ". Am I to (h)igh, too (l)ow, or (c)orrect?" );
                System.out.print( "> " );
                response = keyboard.next();
                
                if ( response.equals("h") ) {
                    hi = guess;
                }
                
                if ( response.equals("l") ) {
                    lo = guess;
                }
            }
            
            System.out.println( "Ha! I am the greatest guesser in the world!" );
            
        }
    }
    
 
    

Code Output