Assignemnt #55 and A Number-Guessing Game
Code
/// Name: Marco Correa
/// Period: 5
/// Program Name: A Number-Guessing Game
/// File Name: NumberGuessingGame.java
/// Date Finished: 11/27/2015
import java.util.Scanner;
public class NumberGuessingGame {
public static void main(String[] args) {
int secretNumber;
secretNumber = (int) (Math.random() * 10 + 1);
System.out.println("Secret number is " + secretNumber);
Scanner keyboard = new Scanner(System.in);
int guess;
System.out.print("Enter a guess: ");
guess = keyboard.nextInt();
System.out.println("Your guess is " + guess);
if (guess == secretNumber)
System.out.println("Your guess is correct. Congratulations!");
else if (guess < secretNumber)
System.out
.println("Your guess is smaller than the secret number.");
else if (guess > secretNumber)
System.out
.println("Your guess is greater than the secret number.");
}
}
Picture of the output