wangmaster

Untitled

Nov 2nd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import java.util.*;
  2. public class RandGuess
  3. {
  4. public static void main(String[] args)
  5. {
  6.  
  7. Scanner guess = new Scanner(System.in);
  8. System.out.print("Make A Guess: ");
  9. int user = guess.nextInt();
  10. Random rand = new Random();
  11. int x = rand.nextInt( 100 ) + 1;
  12. int y = rand.nextInt( 100 ) + 1;
  13.  
  14. while (user > 100 || user < 1)
  15. {
  16. System.out.print("Enter a Number Between 1 and 10");
  17. }
  18. if (user < 100 && user > 1)
  19. {
  20. if (x < y && Math.abs(x-y) < 5)
  21. {
  22. int z = rand.nextInt( y - x ) + x;
  23. if (user == z)
  24. {
  25. System.out.print("That's Right! You're Cool!");
  26. }
  27. if (user != z && (user - z < 3 || z - user < 3))
  28. {
  29. System.out.print(z);
  30. }
  31. while (user != z && (user - z > 3 || z - user > 3))
  32. {
  33. System.out.print("You Missed By a Mile!");
  34. }
  35. }
  36. if (y < x && Math.abs(x-y) < 5)
  37. {
  38. int z = rand.nextInt( x - y ) + y;
  39. if (user == z)
  40. {
  41. System.out.print("That's Right! You're Cool!");
  42. }
  43. if (user != z && (user - z < 3 || z - user < 3))
  44. {
  45. System.out.print(z);
  46. }
  47. while (user != z && (user - z > 3 || z - user > 3))
  48. {
  49. System.out.print("You Missed By a Mile!");
  50. }
  51. }
  52. }
  53. }
  54. }
Add Comment
Please, Sign In to add comment