1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import java.util.*;
  2. import java.util.Random;
  3. /**
  4. * Too Large Too Small Guessing Game.
  5. *
  6. * @jaejoson
  7. * @10/18/2018
  8. */
  9. public class GuessingGame {
  10. public static void main(String[] args) {
  11. double rand = Math.random() * ((50 - 25) + 1) + 25;
  12. double Val = Math.round(rand);
  13. int numberOfTries = 0;
  14. int previousGuess = 0;
  15. while (true) {
  16. Scanner in = new Scanner(System.in);
  17. System.out.print("Guess a number between 25 and 50. ");
  18. int userGuess = in.nextInt();
  19. if (previousGuess != userGuess) {
  20. numberOfTries++;
  21. previousGuess = userGuess;
  22. }
  23. if (userGuess != Val && userGuess > Val) {
  24. System.out.print("Number is waaaay too large! ");
  25. } else if (userGuess != Val && userGuess < Val) {
  26. System.out.print("Number is too small :( ");
  27. } else {
  28. System.out.print("You got the correct guess! ");
  29. System.out.print("It took you " + numberOfTries + " tries.");
  30. break;
  31. }
  32. }
  33. }
  34. }