Assignment 66

import java.util.Scanner;
import java.util.Random;

public class HiLo
{
	public static void main ( String[] args )
	{
        Scanner keyboard = new Scanner(System.in);
		Random r = new Random();

		int answer, guess;
		answer = 1 + r.nextInt(100);
        guess = 0;
        int attempt = 1;
        
        System.out.println("I'm thinking of a number between 1-100. You have seven guesses.");
        
        while (guess !=answer && attempt <= 7)
        {
            System.out.print("Guess #" +attempt+ ": ");
            guess = keyboard.nextInt();
            
            if (guess < answer)
                System.out.println("Sorry, you are too low. Guess again..");
            else if (guess > answer)
                System.out.println("Sorry, you are too high. Guess again.");
                
            attempt++;
        }
        
        if (guess == answer)
            System.out.println("You guessed correctly. Congratulations!");
        else
            System.out.println("Sorry. Better luck next time.");  
    }
}