The following program generates a random number between 1 and 5. A while loop then continuously prompts
Question:
The following program generates a random number between 1 and 5. A while loop then continuously prompts the user to guess the random number. The loop continues until the user guesses the number correctly.
// Create the scanner object to read input from the user
Scanner keyedInput = new Scanner(System.in);
// Declare variables
int randNum; int userGuess = 0;
// Generate a random number between 1 and 5
randNum = (int)(Math.round(Math.random()*5+1));
do { System.out.println("Enter a guess:"); userGuess = keyedInput.nextLine();
if (userGuess == randNum) { System.out.println("Yes, you got it!"); }
else { System.out.println("Sorry, try again!"); }
} while (userGuess != randNum);
Your task is to create A flow chart:
- A program that generates a random number between 1 and 5. A do-while loop then continuously prompts the user to guess the random number. The loop continues until the user guesses the number correctly.
- The flow chart is based upon the code above
- I need help making the flow chart
- Thank you to whoever is helping me, I really appreciate it.
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp