1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import java.util.*;
- import java.util.Random;
- /**
- * Too Large Too Small Guessing Game.
- *
- * @jaejoson
- * @10/18/2018
- */
- public class GuessingGame {
-
- public static void main(String[] args) {
- double rand = Math.random() * ((50 - 25) + 1) + 25;
- double Val = Math.round(rand);
- int numberOfTries = 0;
- int previousGuess = 0;
- while (true) {
- Scanner in = new Scanner(System.in);
- System.out.print("Guess a number between 25 and 50. ");
- int userGuess = in.nextInt();
-
-
- if (previousGuess != userGuess) {
- numberOfTries++;
- previousGuess = userGuess;
- }
-
- if (userGuess != Val && userGuess > Val) {
- System.out.print("Number is waaaay too large! ");
- } else if (userGuess != Val && userGuess < Val) {
- System.out.print("Number is too small :( ");
- } else {
- System.out.print("You got the correct guess! ");
- System.out.print("It took you " + numberOfTries + " tries.");
- break;
- }
-
- }
-
-
-
-
- }
- }
|