Assignemnt #55 A Number-GuessingGame
Code
/// Name: Jake Johnson
/// Period: 7
/// Program Name: ANumberGuessingGame
/// File Name: ANumberGuessingGame.java
/// Date Finished: 12/3/2015
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 secret, guess;
System.out.print("I bet you can't guess my secret number between 1 and 10! But I will let you guess anyways: ");
guess = keyboard.nextInt();
secret = 1 + r.nextInt(10);
if (guess != secret)
{
System.out.println("Nope, it was " + secret + ".");
}
else
{
System.out.println("Yep, it was " + secret + ".");
}
}
}
Picture of the output