Assignment #68 and Reverse Hi-Lo
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: Reverse Hi-Lo
/// File Name: ReverseHiLo.java
/// Date Finished: 11/9/2015
import java.util.Scanner;
public class ReverseHiLo
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int hi = 1000;
int lo = 1;
int guess = (lo+hi)/2;
String n;
System.out.println();
System.out.println( "Think of a number from 1 to 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?" );
n = keyboard.next();
while ( ! n.equals("c") )
{
if ( n.equals("h") )
hi = guess;
else if ( n.equals("l") )
lo = guess;
guess = (hi + lo)/2;
System.out.println( "My guess is " + guess +". Am I too (h)igh, too (l)ow, or (c)orrect?" );
n = keyboard.next();
}
System.out.println();
System.out.println( "Ha! I am the greatest guesser in the WORLD!" );
System.out.println();
}
}