| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /**
- * Created by iyasuwatts on 10/17/17.
- */
- import java.util.*;
-
-
-
- public class NumberGame
- {
-
- public static void main (String [] args)
- {
- // initialise variables
- Random randomNumber = new Random();
- int numberGuess = randomNumber.nextInt(10);
- int numberOfTries = 0;
- Scanner input = new Scanner(System.in);
- int guess;
- boolean win = false;
-
- while (win == false) {
-
- System.out.println("Guess a number between 1 and 10");
-
- guess = input.nextInt();
- numberOfTries++;
-
- if (guess == numberGuess) {
-
- win = true;
- }
- else if (guess < numberGuess) {
- System.out.println("Your guess is too small");
- }
-
- else if (guess > numberGuess) {
- System.out.println("Your guess is too large");
- }
- }
-
- System.out.println("You win!");
- System.out.println("The number was " + numberGuess);
- System.out.println("It only took you " + numberOfTries + " tries");
- }
- }
-
-
-
|