Assignemnt #68 and Reverse Hi-Lo
Code
/// Name: Kyle Ivy
/// Period: 5
/// Program Name: ReverseHiLo
/// File Name: ReverseHiLo.java
/// Date Finished: 1/5/2016
import java.util.Scanner;
public class ReverseHiLo
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int hi, lo, guess;
lo = 1;
hi = 1000;
String answer;
System.out.println( "Think of a number from 1 to 1000. I'll try to guess it. ");
System.out.println( "My first guess is " + (lo + hi)/2 + ". Am I too (h)igh, too (l)ow, or (c)orrect? ");
answer = keyboard.next();
while ( !answer.equals("c")){
if ( answer.equals("h")){
hi = (lo+hi)/2;
System.out.println( "My guess is " +(lo + hi)/2 + ". Am I too (h)igh, too (l)ow, or (c)orrect? ");
}
else if ( answer.equals("l")){
lo = (lo+hi)/2;
System.out.println( "My guess is " +(lo + hi)/2 + ". Am I too (h)igh, too (l)ow, or (c)orrect? ");
}
answer = keyboard.next();
}
if ( answer.equals("c") )
System.out.println( "Ha! I am the greatest guesser in the world! ");
}
}
prog68.PNG