Assignemnt #64 Reverse Hi-Lo
Code
/// Name: JJ Deng
/// Period: 6
/// Program Name: Reverse Hi Lo
/// File Name: HiLoREVE.java
/// Date Finished: 1/9/2015
import java.util.Scanner;
import java.util.InputMismatchException;
import java.util.Random;
public class HiLoREVE
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String answer;
int hi, lo, guess;
hi= 123456;
lo= 1;
guess = (lo + hi)/2;
System.out.println(" Think of a number from 1 to 123456. 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(" > ");
answer = keyboard.next();
while (!answer.equals("c"))
{
if (answer.equals("h"))
{
hi = guess;
guess = (lo + hi)/2;
System.out.println(" My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?");
System.out.print(" > ");
answer = keyboard.next();
}
else if (answer.equals("l"))
{
lo = guess;
guess = (lo + hi)/2;
System.out.println(" My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?");
System.out.print(" > ");
answer = keyboard.next();
}
}
System.out.println("I IS GREAATAAA");
}
}
Picture of the output