Assignment 68
import java.util.Scanner;
public class ReverseHiLo
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int guess = 500;
int lo = 1;
int hi = 1000;
String input = "";
System.out.println("Think of a number between 1-1000. I'll try to guess it.");
while (!input.equals("c"))
{
System.out.print("My guess is " +guess+ ". Am I too (h)igh, too (l)ow, or (c)orrect?\n> ");
input = keyboard.next();
if (guess == 999 && input.equals("l"))
lo = 1000;
else if (input.equals("h"))
hi = guess;
else if (input.equals("l"))
lo = guess;
guess = (hi + lo)/2;
}
System.out.println("\nGood game!");
}
}