Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.*;
  2. public class GuessingGame {
  3.  
  4. public static void main(String[] args) {
  5. //Scanner
  6. Scanner sc = new Scanner (System.in);
  7.  
  8. //Declaring Variables outside of loop.
  9. int endGame;
  10. int max = 10;
  11. int min = 1;
  12. int randomNum = (int) (Math.random() * (max - min + 1)) + min;
  13.  
  14. //Directions
  15. System.out.println("In this game, you only have three guesses, so use them wisely!");
  16.  
  17.  
  18. //This print makes the game look aesthetically pleasing.
  19. System.out.println("--------------------------------------------------------------\n");
  20. //Loop that runs the game until they choose to be done playing.
  21.  
  22. do {
  23.  
  24. //For Loop limits user to 3 guesses.
  25.  
  26. for (int i = 1; i <=3; i++) {
  27.  
  28. System.out.print("Guess the number between 1 and 10: ");
  29. int guess = sc.nextInt();
  30.  
  31. if (guess == randomNum) {
  32. i = 4;
  33. System.out.println("Winner!");
  34. }
  35.  
  36. else if (guess != randomNum) {
  37. System.out.print("Guess " + i + " was Wrong.\n\n");
  38. }
  39. }
  40.  
  41.  
  42. System.out.print("If you would like to play again enter 1. If You would like to quit, enter 2:");
  43. endGame = sc.nextInt();
  44.  
  45. //These if/else statements, once again for the aesthetics of the program.
  46. if (endGame == 1) {
  47. System.out.println("\nNew Round\n---------\n");
  48. }
  49.  
  50. else if (endGame == 2) {
  51. //I just like the way the underlines look.
  52. System.out.println("\n------------");
  53. System.out.println(" Game Ended");
  54. System.out.println("------------");
  55. }
  56.  
  57. }while(endGame==1);
  58.  
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement