Assignment #68 and Reverse Hi-Lo
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Reverse Hi-Lo
///File Name: ReverseHiLo.java
///Date Finished: 10/21/15
import java.util.Scanner;
public class ReverseHiLo
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int hi, lo, guess;
String response;
hi = 1000;
lo = 1;
guess = ( lo + hi ) / 2;
System.out.println( "Think of a number from 1 to 1000. I'll try to guess it." );
System.out.println( "My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?" );
response = keyboard.next();
while ( !response.equals("c"))
{
if ( response.equals("h"))
hi = guess;
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?" );
response = keyboard.next();
}
System.out.println( "Ha! I am the greatest guesser in the World!" );
}
}
Picture of the output