Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The language code is Java. Here is the source codes for both: 1. The following program prompts the user to enter his or her name,

image text in transcribed

The language code is Java. Here is the source codes for both:

1. The following program prompts the user to enter his or her name, and then a number. A for loop is then used to echo back the users name the given number of times:

// Create the scanner object to read input from the user

Scanner keyedInput = new Scanner(System.in);

// Declare variables

int num; String name;

// Get the users name

System.out.println("Please enter your name:"); name = keyedInput.nextLine();

// Get the users age

System.out.println("Please enter a number:"); num = keyedInput.nextInt();

System.out.println("----------------");

// Print out the users name, num times, where num is the user's age

for (int i = 1; i

{ System.out.println(name); }

for (int i = 1; i

{ System.out.println(name); }

2. 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);

Program Control and Flow Charts . Your task is to create two flow charts, one for each of the following: A program that prompts the user to enter their name, and then a number. A for loop is then used to echo back the user's name the given number of times. 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 source code for both of these programs is available above, in the activity. Your task is to take the source code and create the flow charts

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

=+impact member states and MNEs?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago