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