Assignment #68 and Reverse Hi-Lo
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Reverse HiLo
/// File Name: ReverseHiLo.java
/// Date Finished: 12/14/2015/
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-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("Sweet! I Guessed Right!");
}
}
Picture of the output