Assignemnt #68: Reverse Hi-low
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: Reveresehilo
/// File Name: Reversehilo.java
/// Date Finished: 12/17/2015
import java.util.Scanner;
public class Reversehilo
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int hi, lo, guess;
lo = 1;
hi = 1000;
String answer;
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 + " . Is it too (h)igh, too (l)ow, or (c)orrect? " );
answer = keyboard.next();
while ( !answer.equals("c") )
{
if ( answer.equals("h") )
{
hi = guess;
guess = ( guess + lo ) / 2;
System.out.println( " My guess is " + guess + " . Is it too (h)igh, too (l)ow, or (c)orrect? " );
answer = keyboard.next();
if ( answer.equals("l") )
{
lo = guess;
guess = ( guess + hi ) / 2;
System.out.println( " My guess is " + guess + " . Is it too (h)igh, too (l)ow, or (c)orrect? " );
answer = keyboard.next();
}
}
else if ( answer.equals("l") )
{
lo = guess;
guess = ( guess + hi ) / 2;
System.out.println( " My guess is " + guess + " . Is it too (h)igh, too (l)ow, or (c)orrect? " );
answer = keyboard.next();
if ( answer.equals("h") )
{
hi = guess;
guess = ( guess + lo ) / 2;
System.out.println( " My guess is " + guess + " . Is it too (h)igh, too (l)ow, or (c)orrect? " );
answer = keyboard.next();
}
}
}
System.out.println( "The computer is the most efficient means of calculation devised by man " );
}
}
Picture of the output