Assignment # 66 and Hi-Lo with Limited Tries

Code

    /// Name: Tommy Oyuntseren
    /// Period: 7
    /// Program Name: HiLoLimitedTries 
    /// File Name: HiLoLimitedTries.java
    /// Date: 1/11/2016

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

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

		Random r = new Random();

		byte attempts = 0;

		byte guess = 0;
		byte SN = (byte)(1 + r.nextInt(100));
		System.out.print("I'm thinking of a number from 1 to 100. You have 7 attempts to guess it.\n");
       {
	 		while (attempts < 7 && SN!=guess)
			{
				attempts++;
				System.out.print("Guess #"+attempts+" ");
				guess = (byte) keyboard.nextInt();


				if (SN == guess) System.out.println("You guessed it! You must have cheated somehow!");
				else if (SN < guess) System.out.println("Nope, you guessed too high!");
				else System.out.println("Nope, you guessed too low!");
				System.out.println();
			}
			if (attempts >= 7 && SN!=guess) System.out.println("Out of attempts, sorry.(");
		}

		System.out.println();
      
	}
}
  


  

Picture of the output

Assignment 66