Assignemnt #66 Hi-Lo with Limited Tries
Code
///Name: Prooz Fereydouni
///Period: 7
///Project Name: Hi-Lo with Limited Tries
///File Name: HLLT.java
///Date: 1/6/2016
import java.util.Scanner;
import java.util.Random;
public class HLLT
{
public static void main( String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guess, number, gnumber = 0;
number = 1 + r.nextInt(100);
System.out.println("I'm thinking of a number from 1 to 100. You have 7 guesses.");
System.out.print("First guess: ");
guess = keyboard.nextInt();
System.out.println("");
while(guess != number && gnumber<6)
{
if(guessnumber)
{
System.out.println("Wrong! Guess #" + (gnumber + 2) + " Too high. Guess again.");
guess = keyboard.nextInt();
}
gnumber++;
}
if(number == guess)
System.out.println("That's right! My secret number was " + number);
else if(number!=guess)
System.out.println("Sorry, you didn't guess it in 7 tries. You lose! My secret number was " + number);
}
}
Picture of the output