123456789101112131415161718192021222324252627282930313233343536373839 |
- import java.util.Scanner;
- import java.util.Random;
- /**
- * Created by iyasuwatts on 10/17/17.
- */
- public class Main {
-
- public static void main(String[] args){
- Scanner in = new Scanner(System.in);
- System.out.println("Enter a random number between 1 and 10: ");
- Random number = new Random();
- int currentGuess = (number.nextInt(10)+1);
- int currentValue;
- int count = 0;
- int previousValue = 0;
- boolean win = false;
-
- while (win == false) {
- currentValue = in.nextInt();
- if (currentValue != previousValue) {
- count++;
- }
- if (currentValue == currentGuess){
- System.out.println("Correct guess!");
- break;
- } else if (currentValue < currentGuess){
- System.out.println("That guess is too small.");
- } else {
- System.out.println("That guess is too large.");
- }
- previousValue = currentValue;
- }
- System.out.println("You Win!");
- System.out.println("Number of counts to win: " + count);
- count++;
-
- }
- }
|