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