Assignment #68 and Reverse Hi-Lo
Code
///John Mulligan
///period 5
///Program Name: ReverseHiLo
///File Name: ReverseHiLo.java
import java.util.Random;
import java.util.Scanner;
public class ReverseHiLo
{
public static void main(String[] args)
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int hi, lo, guess;
String response;
lo = 1;
hi = 1000;
guess = (lo + hi)/2;
System.out.println("Think of a number between 1 and 1000, and I'll try to guess it");
System.out.println("My guess is " + guess + " am I to (h)igh, (l)ow, or (c)orrect?");
System.out.print("> ");
response = keyboard.next();
while (!response.equals("c"))
{
if (response.equals("h"))
{
hi = guess;
guess = (lo + hi)/2;
System.out.println("My guess is " + guess + " am I to (h)igh, (l)ow, or (c)orrect?");
System.out.print("> ");
response = keyboard.next();
}
else if (response.equals("l"))
{
lo = guess;
guess = (lo + hi)/2;
System.out.println("My guess is " + guess + " am I to (h)igh, (l)ow, or (c)orrect?");
System.out.print("> ");
response = keyboard.next();
}
}
System.out.println("I am best guesser... I dont think thats really a word.");
}
}