Question: Read the code and comments, and fix the program by INSERTING the missing code AND Modify this program so that it reads a String from
Read the code and comments, and fix the program by INSERTING the missing code AND Modify this program so that it reads a String from the user in the following format "First Last" i.e. first name followed by a space followed by last name, then extracts and prints the first and last names. ALL IN JAVA THANK YOU CODE import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First". System.out.println ("Enter your full name as Last, First"); String fullName = scan.nextLine (); // Find the index of the comma in the String entered by the user, // because the comma separates the last name from the first name. int positionOfComma = *** INSERT CALL TO indexOf METHOD HERE ; // Extract the last and first names based on the index of the comma. String lastName = fullName.substring ( *** INSERT PARAMETERS HERE ); String firstName = fullName.substring ( *** INSERT PARAMETERS HERE ); // Print the first name and last name. System.out.println ("First name: " + firstName); System.out.println ("Last name: " + lastName); } // end main } // end ExtractNames
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
