Assignment #68: Reverse Hi-Lo

Code

/// Name: Kiran O'Farrell
/// Program Name: Reverse Hi-Lo
/// File Name: RHL.java
/// Date Completed: 1/20/16

import java.util.Scanner;

public class RHL { 

    public static void main (String[] args) {
  
        Scanner keyboard = new Scanner(System.in);
         
        int hi = 1000;
        int lo = 1;
        int guess = (hi + lo)/2;
        String answer;
            
        System.out.println("Think of a number from 1-1000 and I'll try to guess it.");
        System.out.println("My guess is " + guess + " .");
        System.out.println("Am I too (h)igh, too (l)ow, or (c)orrect?");
        answer = keyboard.next();
        
        while (!answer.equals("c")) {
        
            if (answer.equals("h")) {
        
                hi = guess;
                guess = (hi + lo)/2;
                System.out.println("My guess is " + guess + " .");
                System.out.println("Am I too (h)igh, too (l)ow, or (c)orrect?");
                answer = keyboard.next();
            
            }
        
            if (answer.equals("l")) {
        
                lo = guess;
                guess = (hi + lo)/2;
                System.out.println("My guess is " + guess + " .");
                System.out.println("Am I too (h)igh, too (l)ow, or (c)orrect?");
                answer = keyboard.next();
            
            }
            
        }
        
        if (answer.equals("c")) {
        
            System.out.println("I got it! Awesome!");
            
        }
        
    }
    
}
    

Picture of the output