Random Numbers #55 (Sweet a game)
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name:Number Guessing game
/// File Name: NumberGuessinggame.java
/// Date Finished: 12/1/2015
import java.util.Random;
import java.util.Scanner;
public class NumberGuessingGame
{
public static void main ( String[] args )
{
Random r = new Random();
Scanner input = new Scanner(System.in);
int x = 1 + r.nextInt(10), guess;
System.out.print("I'm thinking of a number from 0 - 10. What is it? ");
guess = input.nextInt();
if (guess == x) {
System.out.println("That's right! My secret number was " + x + "!");
} else {
System.out.println("Sorry, but I was really thinking of " + x + ".");
}
}
}
Picture of the output