Question: JAVA: The do while loop should not be your first choice when writing an iterative solution. As a general rule, if you can solve the

JAVA: The do while loop should not be your first choice when writing an iterative solution. As a general rule, if you can solve the problem reasonably with a while loop then you should do that. With that being said, there is no reason why we can't practice it a little bit.

Ask the user to input a list of their favorite names. We will consider only one word names for this exercise. The user should keep inputting until "x' is entered as the name. Use a do-while loop to get all of the names. When the loop exits, output a string that contains the first initial of each name comma separated.

Hint:

You actually don't need to store each name to solve this. They enter a list but you should only concerned with the first initial.

Refresher

You can get a single character from a string by using the at function. For instance, give the the string

String str = "hello";

I can get the first character like this:

char ch = str.charAt(0); // The character h is assigned to ch

I can also add characters to the end of a string by using the += operator

str+='.';

The string str now contains "hello."

Example run:

Enter a name 'X' to exit

Joe Glenn Hank Bob X

The first letters are: J,G,H,B

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!