Assignemnt #68
Code
/// Name: Ryan Volko
/// Period: 7
/// Program Name: Reverse
/// File Name: Reverse.java
/// Date Finished: 12/15/2015
import java.util.Random;
import java.util.Scanner;
public class Reverse
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int hi = 1000;
int low = 1;
int average = (hi + low)/2;
String x;
System.out.println("Think of a number between 1 and 1000 and i will try and guess it.");
System.out.println("My guess is " + average + ". Am i to (h)igh, to (l)ow, or (c)orrect");
System.out.print("> ");
x = keyboard.next();
System.out.println("");
while (!x.equals("c"))
{
if (x.equals("h"))
{
hi = average;
average = (hi + low)/2;
System.out.println("My guess is " + average + ". Am i to (h)igh, to (l)ow, or (c)orrect");
System.out.print("> ");
x = keyboard.next();
System.out.println("");
}
else if (x.equals("l"))
{
low = average;
average = (hi + low)/2;
System.out.println("My guess is " + average + ". Am i to (h)igh, to (l)ow, or (c)orrect");
System.out.print("> ");
x = keyboard.next();
System.out.println("");
}
}
System.out.println("I got it. I am the best at guessing");
}
}
Picture of the output