Assignment #66 and HiLoLimit
Code
/// Name: Jason Kim
/// Period: 7
/// Program Name: HiLoLimit
/// File Name: HiLoLimit.java
/// Date Finished:11/6/15
import java.util.Random;
import java.util.Scanner;
public class HiLoLimit
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int number = 1 + r.nextInt(100);
System.out.println("I'm thinking of a number between 1-100. You have 7 guesses.");
System.out.print("First guess: ");
int guess = keyboard.nextInt(), tries = 1;
while ( guess != number && tries < 7)
{
tries++;
if (guess > number )
{
System.out.println("Sorry, that guess is too high.");
}
else
{
System.out.println("Sorry, you are too low.");
}
System.out.print("Guess #" + tries + ": ");
guess = keyboard.nextInt();
}
if ( guess == number )
{
System.out.println("You guessed it! What are the odds?!?");
}
else
{
System.out.println("Sorry, you didn't guess it in 7 tries. You lose.");
}
}
}
Picture of the output