Assignemnt #66: Hi-Lo with Limited Tries
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: LimitedHiLo
/// File Name: LimitedHiLo.java
/// Date Finished: 12/7/2015
import java.util.Random;
import java.util.Scanner;
public class LimitedHiLo
{
public static void main(String[] args)
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int guess, x = 1 + r.nextInt(100), tries = 1;
System.out.println("I'm thinking of a number between 1 and 100. You have 7 guesses to guess my number.");
System.out.print("First Guess: ");
guess = keyboard.nextInt();
tries ++;
while ((guess != x) && (tries <= 7))
{
if (guess < x)
System.out.println("Nope, thats not it. Too low, guess again.");
else if (guess > x)
System.out.println("Nope, thats not it. Too high, guess again.");
System.out.print("Guess #" + tries + ": ");
guess = keyboard.nextInt();
tries ++;
}
if (guess == x)
System.out.println("Wow good job you dun guessed it!");
else
System.out.println("too bad. You didn't guees it! better luck next time!");
}
}
Picture of the output