Assignment #68 Reverse Hi-Lo
Code
///Name: Ian Grant
///Period:5
///Project Name: Reverse Hi-Lo
///File Name:RHiLo.java
///12/02/15
import java.util.Scanner;
public class RHiLo
{
public static void main(String[] args)
{
Scanner stuff= new Scanner(System.in);
System.out.println("Think of a number from 1-1000. I'll try to guess it.");
int hi=1000;
int lo=1;
int gus=(lo+hi)/2;
String res="";
System.out.println("My guess is "+gus+". Am I too (h)igh, too (l)ow, or (c)orrect?");
res=stuff.next();
while (!res.equals("c"))
{
if (res.equals("h"))
{
hi=gus;
gus=(lo+hi)/2;
System.out.println("My guess is "+gus+". Am I too (h)igh, too (l)ow, or (c)orrect?");
res=stuff.next();
}
else if (res.equals("l"))
{
lo=gus;
gus=(lo+hi)/2;
System.out.println("My guess is "+gus+". Am I too (h)igh, too (l)ow, or (c)orrect?");
res=stuff.next();
}
else
System.out.println("Please type h or l to symbolize high or low.");
}
System.out.println("Ha! I am the greatest!");
}
}
Output