Assignment #55: Number Guessing Game
Code
/// Name: Kiran O'Farrell
/// Program Name: Number Guesser
/// File Name: NumberGuesser.java
/// Date Completed: 12/2/15
import java.util.Random;
import java.util.Scanner;
public class NumberGuesser {
public static void main (String[] args) {
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int secret = 1 + r.nextInt(10);
int guess;
System.out.println("Try to guess the secret number!");
guess = keyboard.nextInt();
if (guess == secret) {
System.out.println("Great job! You guessed the right number!");
}
else {
System.out.println("Sorry! You guessed the wrong number.");
}
}
}
Picture of the output