12345678910111213141516171819202122232425262728293031323334 |
- /**
- * Created by iyasuwatts on 10/17/17.
- */
- import java.util.Scanner;
- public class Main {
-
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
-
- int mysteryNum = (int) Math.floor(Math.random() * 100 + 1);
- int numOfGuesses = 0;
- int prevGuess = 0;
- int userNum = 0;
- System.out.println("Hey, you! Pick a number between 1 and 100: ");
-
- while (userNum != mysteryNum) {
- userNum = input.nextInt();
- if (userNum < mysteryNum) {
- System.out.println("Too small! Guess again!");
- }
- else if (userNum > mysteryNum) {
- System.out.println("Too large! Guess again!");
- }
- if (prevGuess != userNum) {
- numOfGuesses++;
- }
- prevGuess = userNum;
- }
- System.out.println("Correct guess!");
- System.out.println("It took you " + numOfGuesses + " guess(es) to figure it out!");
- }
- }
-
|