Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guessinggame;
- import java.util.Scanner;
- import java.util.Random;
- public class GuessingGame {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- Random rand = new Random();
- int guessNum = rand.nextInt(20);
- int num = 0;
- System.out.print("This is a guessing game...");
- System.out.print("\nPlease enter a number between one and twenty:");
- num = input.nextInt();
- System.out.print("The number you picked was "+num);
- System.out.print("\nThe random number was "+guessNum);
- if (num == guessNum){
- System.out.print("\nCongrats you guessed the right number!");
- } else {
- System.out.print("\nSorry you did not guess the right number.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement