Assignemnt #55 and A Number Guessing Game
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: A Number Guessing Game
///File Name: ANumberGuessingGame
///Date Finished: 11/12/15
import java.util.Scanner;
import java.util.Random;
public class ANumberGuessingGame
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guessNumber, secretNumber;
secretNumber = 1 + r.nextInt(10);
System.out.println( "I am thinking of a number between 1 and 10, including 1 and 10 " );
System.out.println( "" );
System.out.print( "What is your guess: " );
guessNumber = keyboard.nextInt();
if ( guessNumber == secretNumber )
{
System.out.println( "" );
System.out.println( "You are correct. The number I was thinking was" + secretNumber + "." );
}
else
{
System.out.println( "" );
System.out.println( "Sorry , but the number I was thinking was " + secretNumber + "." );
}
}
}
Picture of the output