Assignemnt #67
Code
/// Name: Daniel Nguyen
/// Period: 6
/// Program Name: revhilo Program
/// File Name: revhilo.java
/// Date Finished: 9/9/2015
import java.util.Scanner;
public class revhilo
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String correct = "c";
String taco = "";
int hi = 1000;
int low = 0;
System.out.println("Think of a number from 1 to 1000. I'll try to guess it.");
while (taco.compareTo(correct) != 0) {
int guess = (hi + low) / 2;
System.out.println("My guess is " + guess + " am I too (h)igh, (l)ow, or (c)orrect?");
System.out.print("> ");
taco = keyboard.next();
if (taco.compareTo("h") == 0) {
hi = guess;
}
if (taco.compareTo("l") == 0) {
low = guess;
}
}
System.out.println("Got it!");
}
}
Picture of the output