Guest User

Untitled

a guest
Feb 20th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. public class GuessNumber{
  5.  
  6.  
  7. public static void main(String[] args) {
  8.  
  9. System.out.println("Welcome to the Guess the Number Game");
  10. System.out.println("++++++++++++++++++++++++++++++++++++");
  11. System.out.println("");
  12.  
  13. int random, guess, attempts;
  14. Scanner sc = new Scanner(System.in);
  15. String choice = "y";
  16. Random generator = new Random();
  17. random = generator.nextInt(100) + 1;
  18. attempts = 1;
  19.  
  20.  
  21. System.out.println("I'm thinking of a number from 1 to 100.");
  22. System.out.println("Try to guess it");
  23. System.out.println("");
  24. System.out.print("Enter Number: ");
  25.  
  26.  
  27. guess = sc.nextInt();
  28. while (guess != random) {
  29. if (guess - random > 10)
  30. {
  31. System.out.println("Way too high! Guess Again.");
  32. System.out.println("");
  33. System.out.println("");
  34. System.out.print("Enter Number: ");
  35. attempts += 1;
  36. }
  37. else if (guess - random < 10)
  38. {
  39. System.out.println("Way too low! Guess Again.");
  40. System.out.println("");
  41. System.out.println("");
  42. System.out.print("Enter Number: ");
  43. attempts += 1;
  44. }
  45. else if (guess > random) {
  46. System.out.print("Too High! Guess again.");
  47. System.out.println("");
  48. System.out.println("");
  49. System.out.print("Enter Number: ");
  50. attempts += 1;
  51. }
  52. else {
  53. System.out.print("Too Low! Guess again.");
  54. System.out.println("");
  55. System.out.println("");
  56. System.out.print("Enter Number: ");
  57. attempts +=1;
  58. }
  59. guess = sc.nextInt();
  60. }
  61.  
  62. if (attempts <=3){
  63. System.out.println("Great work! You are a mathematical wizard.");
  64.  
  65. }else if(attempts >3 && attempts <=7){
  66. System.out.println("Not too bad! You've got some potential.");
  67.  
  68. }else{
  69. System.out.println("What took you so long? Maybe you should take some lessons.");
  70. }
  71. System.out.println("You got it in " + attempts + " tries.");
  72.  
  73.  
  74. }
  75.  
  76. }
Add Comment
Please, Sign In to add comment