Assignemnt #68 Reverse Hi Lo
Code
///Name: Morgan Kaplan
///Period: 5
///Project Name: Reverse Hi Lo
///File Name: RHL.java
import java.util.Scanner;
public class RHL
{
public static void main( String[] args)
{
Scanner momo= new Scanner(System.in);
int h= 1000, l=1, x = ( h + l)/2 ;
String number;
System.out.println( "Think of a number between 1-1000 and I will try to guess it.");
System.out.println( " My guess is " + x + ". Is that too high= \"h\", low= \"l\" or correct= \"c\"? " );
number=momo.next();
while ( ! number.equals("c"))
{
if ( number.equals("l"))
{
l=x;
x = ( h + l)/2 ;
System.out.println( " My guess is " + x + " Is that too high= \"h\", low= \"l\" or correct= \"c\"? " );
number=momo.next();
}
else if (number.equals("h"))
{
h=x;
x = ( h + l)/2 ;
System.out.println( " My guess is " + x + " Is that too high= \"h\", low= \"l\" or correct= \"c\"? " );
number=momo.next();
}
}
}
}
Picture of Output