Assignemnt #55: A Number-Guessing Game
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: NumberGuessingGame
/// File Name: NumberGuessingGame.java
/// Date Finished: 12/3/2015
import java.util.Scanner;
import java.util.Random;
public class NumberGuessingGame
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int num = 1 + r.nextInt(10), guess;
System.out.println("I'm thinking of a number from 1 to 10. Can you guess what it is?");
System.out.print("Your Guess: ");
guess = keyboard.nextInt();
System.out.println();
if (num == guess)
System.out.println("Wow good job you dun guessed me number!");
else if (num != guess)
System.out.println("Nope, thats not the one. I was thinking of " + num );
}
}
Picture of the output