Assignemnt #68 Reverse Hi-Lo
Code
//Tyler Hart
//period 5
//RHiLo.java
//HiLo With Limited Tries
//12/7/2015
import java.util.Scanner;
public class RHiLo
{
public static void main( String [] args)
{
Scanner key = new Scanner(System.in);
System.out.println("Think of a Number 1-100?");
System.out.println("my guess is 500. Am I Too (h)igh, too (l)ow, or (c)orrect?");
String d2 = key.next();
int lo=1, hi=1000,n=500;
while (!d2.equals("c"))
{
if (d2.equals("h"))
{
hi = n;
n = ( lo + hi ) / 2;
System.out.println("my guess is "+n+". Am I Too (h)igh, too (l)ow, or (c)orrect?");
d2 = key.next();
}
else if (d2.equals("l"))
{
lo = n;
n = ( lo + hi ) / 2;
System.out.println("my guess is "+n+". Am I Too (h)igh, too (l)ow, or (c)orrect?");
d2 = key.next();
}
}
}
}
Picture of the output