Assignemnt #68 and Keep On Guessing
Code
///Name: Daniel Tiffany- Appleton
///Period: 7
///Program Name: Keep On Guessing
///Fill Name: KeepOnGuessing
///Date Finished: 11/16/15
import java.util.Random;
import java.util.Scanner;
public class KeepOnGuessing
{
public static void main( String [] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guess, hi, lo;
String answer, c, h, l;
System.out.println( "Thinking of a number between 1-1000. I'll try to guess it.");
hi = 1000;
lo = 1;
guess = ( lo + hi ) / 2;
System.out.println( "" );
System.out.println( "My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?" );
answer = keyboard.next();
while( ! answer.equals("c"))
{
if (answer.equals("h"))
{
hi = guess;
}
else if (answer.equals("l"))
{
lo = guess;
}
guess = ( lo + hi ) / 2;
System.out.println( "" );
System.out.println( "My guess is " + guess + ". Am I too (h)igh, too (l)ow, or (c)orrect?" );
answer = keyboard.next();
}
System.out.println( "" );
System.out.println( "I am the master guesser in the UNIVERSE!");
}
}
Picture of the output