Main.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. /**
  4. * Created by iyasuwatts on 10/17/17.
  5. */
  6. public class Main {
  7. public static void main(String[] args){
  8. Scanner in = new Scanner(System.in);
  9. System.out.println("Enter a random number between 1 and 10: ");
  10. Random number = new Random();
  11. int currentGuess = (number.nextInt(10)+1);
  12. int currentValue;
  13. int count = 0;
  14. int previousValue = 0;
  15. boolean win = false;
  16. while (win == false) {
  17. currentValue = in.nextInt();
  18. if (currentValue != previousValue) {
  19. count++;
  20. }
  21. if (currentValue == currentGuess){
  22. System.out.println("Correct guess!");
  23. break;
  24. } else if (currentValue < currentGuess){
  25. System.out.println("That guess is too small.");
  26. } else {
  27. System.out.println("That guess is too large.");
  28. }
  29. previousValue = currentValue;
  30. }
  31. System.out.println("You Win!");
  32. System.out.println("Number of counts to win: " + count);
  33. count++;
  34. }
  35. }