Main.java 1006B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Created by iyasuwatts on 10/17/17.
  3. */
  4. import java.util.Scanner;
  5. public class Main {
  6. public static void main(String[] args){
  7. Scanner input = new Scanner(System.in);
  8. int mysteryNum = (int) Math.floor(Math.random() * 100 + 1);
  9. int numOfGuesses = 0;
  10. int prevGuess = 0;
  11. int userNum = 0;
  12. System.out.println("Hey, you! Pick a number between 1 and 100: ");
  13. while (userNum != mysteryNum) {
  14. userNum = input.nextInt();
  15. if (userNum < mysteryNum) {
  16. System.out.println("Too small! Guess again!");
  17. }
  18. else if (userNum > mysteryNum) {
  19. System.out.println("Too large! Guess again!");
  20. }
  21. if (prevGuess != userNum) {
  22. numOfGuesses++;
  23. }
  24. prevGuess = userNum;
  25. }
  26. System.out.println("Correct guess!");
  27. System.out.println("It took you " + numOfGuesses + " guess(es) to figure it out!");
  28. }
  29. }