Assignemnt #55

Code

/// Name: Sam Menar
/// Period: 6
/// Program Name: NumberGuessingGame
/// File Name: NumberGuessingGame.java
/// Date Finished: 11/30/15

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

public class NumberGuessingGame
{
	public static void main ( String[] args )
	{
		Random r = new Random();
        
        int choice = 1 + r.nextInt(10);
        
        int guess;
        
        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("I'm thinking of a number from 1 to 10.");
        System.out.println(" ");
        System.out.print("Your guess: ");
        guess = keyboard.nextInt();
        
        if ( guess == choice )
        {
            System.out.println("Congradulations you got it right!");
        }
        else 
        {
            System.out.println("Sorry, but I was really thinking of " + choice );
        }
    }
}

                       
    

Picture of the output

Assignment 49