Site Loader

  System.out.print(“Welcome.
“);        System.out.print(“You are now playing a game that will give you a random generated number between 1 and the number you chose
“);        System.out.print(“Choose wisely:

“);        Scanner scan = new Scanner(System.in);  // This is the number the user will input of the start of the game so the computer knows the limit on where it generates a number        int max;        max = scan.nextInt();        Random randomNum = new Random();        int num = randomNum.nextInt(max);        int tries = 0; // This number will change (or stay the same) depending on how many guesses the user takes to find the unknown number        Scanner input2 = new Scanner(System.in);        int guess;        boolean playerWin = false;        while (playerWin == false){  // This while loop keeps repeating until the user guesses the right number            System.out.print (“Now start guessing between 1 “+ num +”:
“);            guess = input2.nextInt();            tries++; // Refers back to tries = 0 will keep adding 1 to the guess count until the user gets it right            if (guess == num){                playerWin = true; // This is the first thing the input number will go through to check if it is a winning number or not                                  // If the number is guessed first try playerWin = true and the game will end if not it will keep going through the loop                                              }            else if(guess num){                System.out.print(“Your guess was too high, try again!”);                                 // Third phase of the loop the number is checked to see if it was too low or too high                                  // If too low the player will be prompted to guess again            }        }                                 // When the user gets the correct number the text below will print out        System.out.print(“Congratulations!! You have won the game /n”);

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

Post Author: admin

x

Hi!
I'm Rhonda!

Would you like to get a custom essay? How about receiving a customized one?

Check it out