12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /**
- * Created by iyasuwatts on 10/17/17.
- */
- import java.util.Scanner;
- import java.util.Random;
- public class Main {
-
- public static void main(String[] args){
-
- Scanner s = new Scanner(System.in);
-
- Random rand = new Random();
- int magicNum = rand.nextInt(10) + 1; //Generate a random number between 1 and 10
- int currGuess = -1;
- int previousGuess = -2;
- int guessCount = 0;
-
- System.out.println("It's a guessing game! Guess the magic number! It's between 1 and 10!");
- System.out.print("Guess a number: ");
-
- while (magicNum != currGuess) {
- currGuess = s.nextInt();
- if (currGuess != previousGuess) {
- guessCount++;
- }
- if (currGuess == magicNum) {
- System.out.println("Congrats! You guessed the magic number in "
- + guessCount + " guesses!");
- }
- else if (currGuess < magicNum) {
- System.out.print("Too low! Guess a number: ");
- }
- else if (currGuess > magicNum) {
- System.out.print("Too high! Guess a number: ");
- }
- previousGuess = currGuess;
- }
-
- s.close();
-
- }
- }
|