Advertisement
JackHoughton00

Guessing Game

Mar 5th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. package guessinggame;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4.  
  5. public class GuessingGame {
  6.  
  7. public static void main(String[] args) {
  8. Scanner input = new Scanner(System.in);
  9. Random rand = new Random();
  10. int guessNum = rand.nextInt(20);
  11. int num = 0;
  12. System.out.print("This is a guessing game...");
  13. System.out.print("\nPlease enter a number between one and twenty:");
  14. num = input.nextInt();
  15. System.out.print("The number you picked was "+num);
  16. System.out.print("\nThe random number was "+guessNum);
  17. if (num == guessNum){
  18. System.out.print("\nCongrats you guessed the right number!");
  19. } else {
  20. System.out.print("\nSorry you did not guess the right number.");
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement