Assignment #55 and A Number-Guessing Game
Code
/// Name: Brendan Baird
/// Period: 6
/// Program Name: A Number-Guessing Game
/// File Name: BetterNumberGuessing.java
/// Date Finished: 10/30/2015
import java.util.Scanner;
import java.util.Random;
public class BetterNumberGuessing
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int secretNumber = 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 == secretNumber)
System.out.println("That's right! My secret number was " + secretNumber + "!");
else
System.out.println("Wrong! The number I was thinking of was " + secretNumber + "!");
}
}
Picture of the output