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