Assignemnt #68
Code
///colin hinton
///5th period
///Guess
///Guess.java
///11/6/2015
import java.util.Scanner;
class Guess
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
String guess;
int hi, lo, average;
hi = 1000;
lo = 1;
average = ((hi + lo) / 2);
System.out.println("THINK OF A NUMBER BETWEEN 1-1000 AND ILL GUESS IT");
System.out.println("My guess is " + average + " . Am I too (h)igh, too(l)ow, or (c)orrect?");
guess = keyboard.next();
while (guess.equals("h"))
{
hi = average;
average = ((hi + lo) /2);
System.out.println("My guess is " + average + " . Am I too (h)igh, too(l)ow, or (c)orrect?");
guess = keyboard.next();
}
while (guess.equals("l"))
{
lo = average;
average = ((hi + lo) /2 );
System.out.println("My guess is " + average + " . Am I too (h)igh, too(l)ow, or (c)orrect?");
guess = keyboard.next();
}
if (guess.equals("c"))
{
System.out.println("I AM THE BESTEST GUESSAR EVAR! BECAUSE I GUESSED " + average);
}
}
}
Picture of the output