Assignment #68 and Reverse Hi-Lo
Code
//Name: Mark Katz
///Period: 6
///Program Name: Reverse Hi Lo
///File Name: rhilo.java
///Date Finished: 10/28/15
import java.util.Scanner;
public class rhilo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int hi, lo, guess;
lo = 1;
hi = 1000;
guess = (lo + hi)/2;
String response;
System.out.println( "Think of a number from 1 to 1000. Ill 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( ">" );
response = keyboard.next();
while (!response.equals("c"))
{
if (response.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( ">" );
response = keyboard.next();
}
else if (response.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( ">" );
response = keyboard.next();
}
}
System.out.println( "Ha! I am the greatest guesser in the WORLD!" );
}
}
Picture of the output