Assignment #55 and Better Number Guessing Game
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Better Number Guessing Game
/// File Name: NumberGuessingGame.java
/// Date Finished: 12/01/2015/
import java.util.Random;
import java.util.Scanner;
public class NumberGuessingGame
{
public static void main (String[] args)
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int guess, snumber = 1 + r.nextInt(10);
System.out.println("I'm thinking of a number between 1-10");
System.out.println("Try to guess it!");
System.out.print("> ");
guess = keyboard.nextInt();
if ( guess == snumber )
{
System.out.println("Congrats! You guessed the right number!");
}
else
{
System.out.println("Sorry, the number I was thinking of was " + snumber );
}
}
}
Picture of the output