Guest User

Untitled

a guest
Nov 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4.  
  5. public class guessIt
  6. {
  7. public static void main(String[] args)
  8. {
  9.  
  10. Random myRandom = new Random();
  11. Scanner myScanner = new Scanner(System.in);
  12. int userTry;
  13. int rndNum = myRandom.nextInt(10);
  14. int tryCounter = 2;
  15. String tryName = " tries";
  16. System.out.println("Welcome to the Guessing Game!");
  17. System.out.println("You have three chances to guess the number between 0-9");
  18.  
  19.  
  20.  
  21. do
  22. {
  23.  
  24.  
  25. if (tryCounter <= 1) // changes Tries to try when Tries
  26. {
  27. tryName = " try ";
  28. }
  29. userTry = myScanner.nextInt();
  30.  
  31. if(rndNum == userTry)
  32. {
  33. System.out.print("You WIN!");
  34. break;
  35. }
  36.  
  37. else if(rndNum > userTry)
  38. {
  39.  
  40. System.out.println("You have "+ tryCounter + tryName +" left");
  41. System.out.print("You have guessed to low: ");
  42. tryCounter--;
  43.  
  44. }
  45.  
  46.  
  47. else if(rndNum < userTry)
  48. {
  49.  
  50. System.out.println("You have "+ tryCounter + tryName +" left");
  51. System.out.print("You have guessed to high: ");
  52. tryCounter--;
  53.  
  54.  
  55. }
  56.  
  57.  
  58. else {
  59. System.out.println("It broked");
  60. }
  61.  
  62.  
  63. }while (tryCounter >= 0);
  64.  
  65.  
  66. }
  67.  
  68. }
Add Comment
Please, Sign In to add comment