6.) Name

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

↳ 5 This line constructs the final formatted name string. It takes the first letter of the last_name, adds a period and a comma, and then appends the first_name.

String final_name = last_name.substring(0,1) + "., " + first_name;

↳ 3 This line extracts the first name from the parts array and stores it in the variable first_name.

String first_name = parts[0];

↳ 1 This line reads a full name entered by the user as a single string and stores it in the variable full_name.

String full_name = scnr.nextLine();

↳ 4 This line extracts the last name from the parts array and stores it in the variable last_name. It accesses the last element of the array using parts.length - 1.

String last_name = parts[parts.length - 1];

↳ 7 Construct the second line of the if statement that extracts the first letter of the middle name and stores it in the variable middle.

String middle = parts[1].substring(0,1);

↳ 2 This line splits the full_name string into an array of strings, using a space (" ") as the delimiter. Each part of the name (first name, middle name, last name) will be stored as a separate element in the parts array.

String[] parts = full_name.split(" ");

↳ 9 Construct the line that prints the final_name to the console.

System.out.println(final_name);

↳ 8 Construct the third line and final line of the if statement that If a middle name was provided, will append a space, the middle initial, and a period to the final_name.

final_name += " " + middle + "."; }

↳ 6 Construct the first line of an if statement that checks if there are more than two elements in the parts array, which indicates that a middle name was provided.

if (parts.length >2) {


Ensembles d'études connexes

PTEC2033 Quiz 10 [Fall 2018] - Ergonomics, Slips, Trips, & Fall, & Bloodborne Pathogens

View Set

214 Unit 24- FL statutes for Annuity contracts Only

View Set

Audio Processing Techniques MIDTERM

View Set

Macroeconomics (ECON 2120) Chapter 9 Employment and Unemployment

View Set