Assignment 68; RevHiLo
Code
// Donovan Rich
// Period 6
// Reverse Hi-Lo
// RevHiLo.java
// 12/14/2015
import java.util.Scanner;
public class RevHiLo
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int guess, hi=1000, lo=1;
String rep="";
System.out.println( "Think of a number between 1 and 1000." );
while ( !rep.equals("c") )
{
guess = (hi+lo)/2;
System.out.println( "My guess is " + guess + ". (h)igh, (l)ow, or (c)orrect?" );
rep = keyboard.next();
if ( rep.equals( "h" ) )
hi = guess;
if ( rep.equals( "l" ) )
lo = guess;
}
System.out.println( "Knew it! I am amazing." );
}
}
Picture of the output