Advertisement
williamlangdoc

Untitled

Oct 12th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package com.William;
  2. import java.util.*;
  3. public class gangstasName
  4. {
  5. public static void main(String[] args)
  6. {
  7. Random random = new Random();
  8. int number = random.nextInt(10) + 1;
  9. Scanner input = new Scanner(System.in);
  10. System.out.print("guess a number between 1 and 10");
  11. int guess = input.nextInt();
  12. int wrongHowClose = number-guess;
  13. int howClose = Math.abs(wrongHowClose);
  14. if(guess < 1 || guess > 10)
  15. {
  16. System.out.print("that is an invalid number");
  17. System.exit(0);
  18. }
  19.  
  20. if (guess == number)
  21. {
  22. System.out.print("im proud of you");
  23. }
  24. else {
  25. if (howClose >= 3) {
  26. System.out.println("you were so far off");
  27. } else
  28. {
  29. System.out.println("so close");
  30. }
  31. System.out.print("better luck next time");
  32. }
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement