Assignemnt #68: Reverse Hi-Lo

Code

    /// Name: Kelsey Lieberman
    /// Period 5
    /// Program Name: ReverseHiLo
    /// File Name: ReverseHiLo.java
    /// Date Finished: 12/9/2015
    
import java.util.Scanner;

public class ReverseHiLo
{
    public static void main(String args[])
    {
        Scanner key = new Scanner (System.in);
        
        int h = 1000, l = 1, guess = 500;
        String ans;
        
        System.out.println("Think of a number from 1-1000 and I'll try to guess it.");
        System.out.println("My guess is " + guess + ". Is that too (h)igh, too (l)ow, or (c)orrect?");
        System.out.print("> ");
        ans = key.next();
            if (ans.equals("h"))
                h = guess;
            else if (ans.equals("l"))
                l = guess;
        while (!ans.equals("c"))
        {
            guess = ((h+l)/2);
            System.out.println("My guess is " + guess + ". Is that too (h)igh, too (l)ow, or (c)orrect?");
            ans = key.next();
                if (ans.equals("h"))
                    h = guess;
                else if (ans.equals("l"))
                    l = guess;
        }
        
        System.out.println("Ha! I'm da bes!");
    }
}
    

Picture of the output

Assignment 68