RHilo
Code
import java.util.Scanner;
public class RHilo
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int lo, hi, guess;
String ans;
lo = 1;
hi = 1000;
guess = (( lo+hi )/2);
System.out.println( " Think of a number from 1-1000" );
System.out.println( " say high if its to (h)high, (l)low if its low, or (c)correct if its right" );
System.out.println( "my guess is " + guess );
ans = keyboard.next();
while ( !ans.equals("c"))
{
if ( ans.equals("h") )
{
hi = guess;
guess = ((hi+lo)/2);
}
else if ( ans.equals("l"))
{
lo = guess;
guess = ((hi+lo)/2);
}
System.out.println( " say high if its to (h)high, (l)low if its low, or (c)correct if its right" );
System.out.println( "my guess is " + guess );
ans = keyboard.next();
}
if ( ans.equals("c"))
{
System.out.println( " I'm just to good" );
}
}
}
RHilo