Assignemnt #68

Code

/// Name: Sam Menar
/// Period: 6
/// Program Name: Reverse Hi Lo
/// File Name: ReverseHiLo.java
/// Date Finished: 1/6/16

import java.util.Scanner;
public class ReverseHiLo
{
    public static void main( String[] args )
    {
        int hi = 1000, lo = 1, guess;
        guess = ( hi + lo ) / 2;
        String r;
        
        Scanner keyboard = new Scanner(System.in);
        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("> ");
        r = keyboard.next();
        
        while ( !r.equals("c"))
        {
            if ( r.equals("h"))
            {
                hi = guess;
                guess = ( hi + lo ) / 2;
                System.out.println("My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?");
                System.out.print("> ");
                r = keyboard.next();
            }
            else if ( r.equals("l"))
            {
                lo = guess;
                guess = ( hi + lo ) / 2;
                System.out.println("My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?");
                System.out.print("> ");
                r = keyboard.next();
            }
        }
        System.out.println("Ha! I am the greatest guesser ever!");
    }
}
                
                
                

            


    

Picture of the output

Assignment 13