Assignment #55 and A Number-Guessing Game
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: A Number-Guessing Game
/// File Name: NumberGuess.java
/// Date Finished: 10/7/2015
import java.util.Random;
import java.util.Scanner;
public class NumberGuess
{
public static void main ( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int choice = 1 + r.nextInt(10);
int guess;
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 == choice )
{
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