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