Code
/// Name: Afaf Nabeeha
/// Period: 7
/// Program Name: A Number-Guessing Game
/// File Name: Game.java
/// Date Finished: 11/31/2015 public class Game
import java.util.Random;
import java.util.Scanner;
public class Game
{
public static void main( String[] args )
{
Random r = new Random();
int myNumber, uNumber;
myNumber = 1 + r.nextInt(10);
Scanner keyboard = new Scanner(System.in);
System.out.println( "I'm thinking of a number from 1 to 10. " );
System.out.print( "Your guess: " );
uNumber= keyboard.nextInt();
System.out.println();
if ( uNumber == myNumber )
{
System.out.println( "That's right! My secret number was " + myNumber + "!" );
}
else if ( uNumber != myNumber )
{
System.out.println( "Sorry, but I was really thinking of " + myNumber + "." );
}
else
{
System.out.println( "Error." );
}
}
}
Picture of the output