123456789101112131415161718192021222324252627282930313233343536373839 |
- /**
- * Created by iyasuwatts on 10/17/17.
- */
- public class Main {
-
- int randomNum;
- int counterTooBig = 0;
- int counterTooSmall = 0;
- int totalGuesses = 0;
- int prevGuess = 0;
- int currentGuess = 0;
-
- public static void main(String[] args){
- System.out.println("You have 5 chances to correctly guess a random number between 1 and 20.");
- Scanner input = new Scanner(System.in);
- Random random = new Random();
- randomNum = 1+random.nextInt(20);
- System.out.println("Enter your first guess now: ");
- for (int i = 1; i <= 5; i++){
- currentGuess = input.getNextInt();
- if (currentGuess == prevGuess) {
- i=i-1;
- System.out.println("Same as your last guess...Try Again")
- }
- if (currentGuess == randomNum) {
- System.out.println("*** Correct!!! ***");
- System.out.println("Total guesses to win: " + i);
- }else if (currentGuess > randomNum) {
- System.out.println("TOO BIG");
- System.out.println("Total guesses remaining: " + (5-i));
- } else if (currentGuess < randomNum) {
- System.out.println("too small");
- System.out.println("Total guesses remaining: " + (5-i));
- prevGuess = currentGuess;
- }
- }
- }
- }
|