Assignment #X

Code

///jack newsom
///period 5
///program RevHiLo
///filename RevHiLo
///date completed 10/8/15

import java.util.Scanner;

public class RevHiLo
{
    public static void main( String[] args )
    {
        Scanner bot = new Scanner(System.in);
        
        System.out.println("Think of a number between 1 and 1000. I'll try to guess it.");
        int lo = 1;
        int hi = 1000;
        int guess = (hi + lo)/2;
        
        System.out.println("My guess is 500. Am I too (h)igh, (l)ow, or (c)orrect?");
        String ans = bot.next();
        
        boolean bAns = ans.equals("c");
        
        while ( bAns != true )
        {
            boolean bAnsHi = ans.equals("h");
            boolean bAnsLo = ans.equals("l");
            
            if ( bAnsHi == true )
            {
                hi = guess;
                
                guess = (lo + hi)/2;
                System.out.println("My guess is " + guess + ". Am I too (h)igh, (l)ow, or (c)orrect?");
                ans = bot.next();
                
            }
            else if ( bAnsLo == true )
            {
                lo = guess;
                
                guess = (lo + hi)/2;
                System.out.println("My guess is " + guess + ". Am I too (h)igh, (l)ow, or (c)orrect?");
                ans = bot.next();
                
            }
            
            bAns = ans.equals("c");
            
        }
        
        System.out.println("Ha! I am the greatest guesser in the world!");
    }
}      
    

Picture of the output

Assignment X