Assignment # 68 and Reverse Hi-Lo
Code
/// Name: Tommy Oyuntseren
/// Period: 7
/// Program Name: RevHiLo
/// File Name: RevHiLo.java
/// Date: 1/11/2016
import java.util.Scanner;
public class RevHiLo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int upLim = 1001;
int loLim = 0;
String read = "";
int guess = 0;
byte attempts = 0;
System.out.println("Think of a number from 1 to 1000 and I'll guess it.\n");
{
do
{
guess = (int)( Math.floor((upLim-loLim) / 2) + loLim);
if (guess==0) guess = 1;
attempts++;
System.out.println("My guess is "+guess);
System.out.println("Is it too low (l), high (h) or correct (c)?");
System.out.print("It is: ");
read = keyboard.next();
switch (read)
{
case "h": upLim = guess;
break;
case "l": loLim = guess;
break;
case "c": read = "STV";
break;
default: System.out.println("WRONG INPUT!!!");
}
}
while (!read.equals("STV"));
System.out.println("I guessed!!! It was "+guess+". It only took me "+attempts+" attempts to guess!!!");
}
System.out.println();
}
}
Picture of the output