Assignment #68 and Reverse Hi-Lo
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: Reverse Hi-Lo
/// File Name: ReverseHiLo.java
/// Date Finished: 10/15/2015
import java.util.Scanner;
public class ReverseHiLo
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int lo = 1, hi = 1000, guess = ( lo + hi ) / 2;
String answer;
System.out.println( "Think of a number between 1-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?" );
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( "\nHa! I am the greatest guesser in the WORLD!" );
}
}
Picture of the output