Assignment #66 and Hi-Lo with Limited Tries

Code

         //Name: Mark Katz
    ///Period: 6
    ///Program Name: Hi-Lo with Limited Tries
    ///File Name: hilo2.java
    ///Date Finished: 10/21/15 
    
import java.util.Random;
    import java.util.Scanner;
    
    public class hilo2
    {
        public static void main(String[] args)
        {
            Random r = new Random();
            Scanner keyboard = new Scanner(System.in);
            
            int snumber, guess, n;
            
            snumber = 1 + r.nextInt(100);
            n = 0;
            System.out.println("I'm thinking of a number between 1-100. You have 7 guesses. Good luck!");
            System.out.print("Guess #" + (n+1) + ": ");
            guess = keyboard.nextInt();
            System.out.println("");
            n++;
            
            while (guess != snumber && n < 7)
            {
                if (guess > snumber)
                {
                    System.out.println("You were a little high.");
                    System.out.print("Guess #" + (n+1) + ": ");
                    guess = keyboard.nextInt();
                    System.out.println("");
                    n++;
                }
                
                else if (guess < snumber)
                {
                    System.out.println("You were a little low.");
                    System.out.print("Guess #" + (n+1) + ": ");
                    guess = keyboard.nextInt();
                    System.out.println("");
                    n++;
                }
            }
            
            if (guess == snumber)
            {
                System.out.println("You got it!");
            }
            
            else if (n >= 7)
            {
                System.out.println("Sorry you ran out of tries. you lose.");
            }
        }
    }

    

Picture of the output

Assignment66