Assignment #55 and NumberGuessingGame
Code
/// Name: Jason Kim
/// Period: 7
/// Program Name: NumberGuessingGame
/// File Name: NumberGuessingGame.java
/// Date Finished:10/27/15
import java.util.Scanner;
import java.util.Random;
public class NumberGuessingGame
{
public static void main (String[] args)
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int secretNumber = 1 + r.nextInt(10), number;
System.out.println("I'm thinking of a number from 1 to 10.");
System.out.print("Your guess: ");
number = keyboard.nextInt();
System.out.println();
if ( number == secretNumber )
{
System.out.println("That's right! My secret number was " + secretNumber + "!");
}
else
{
System.out.println("Sorry, but I was really thinking of " + secretNumber + ".");
}
}
}
Picture of the output