Assignment #66 and Hi-lo With Limited Tries
Code
///John Mulligan
///period 5
///Program Name: HiLoLimited
///File Name: HiLoLimited.java
import java.util.Random;
import java.util.Scanner;
public class HiLoLimited
{
public static void main( String[] args )
{
Scanner bot = new Scanner(System.in);
Random r = new Random();
System.out.println("I'm thinking of a number between 1-100. You got 7 guesses.");
System.out.print("First guess: ");
int guess = bot.nextInt();
int tries = 0;
tries++;
int actual = r.nextInt(99) + 1;
while ( guess != actual && tries <7 )
{
if ( guess > actual )
{
System.out.println("Your too high.");
tries++;
System.out.println("Guess #" + tries + ": " );
guess = bot.nextInt();
}
else
{
System.out.println("Your too low.");
tries++;
System.out.println("Guess #" + tries + ": " );
guess = bot.nextInt();
}
}
if ( tries <= 7 && guess == actual )
System.out.println("You guessed it??? WAT?!");
else
System.out.println("Sorry, you're out of tries. You lose. Good day sir. (The number was " + actual + " )");
}
}