Assignemnt #68 Reverse Hi-Lo
Code
///Name: Prooz Fereydouni
///Period: 7
///Project Name: Reverse Hi-Lo
///File Name: RHL.java
///Date: 1/12/2016
import java.util.Scanner;
public class RHL
{
public static void main( String[] args)
{
Scanner keyboard = new Scanner(System.in);
int hi=0, lo=1001;
String guess="";
System.out.println("Think of a number from 1 to 1000. I'll try to guess it.");
while(!guess.equals("c"))
{
System.out.println("My guess is " + ((hi+lo)/2) + ". Am I too (h)igh, too (l)ow, or (c)orrect?");
guess = keyboard.next();
if(guess.equals("h"))
{
lo=(hi+lo)/2;
}
else if(guess.equals("l"))
{
hi=(hi+lo)/2;
}
else
{
if(!guess.equals("c"))
{
System.out.println("Wrong Input!");
return;
}
}
}
System.out.println("Ha! I am the greatest guesser in the WORLD!");
}
}
Picture of the output