Many documents use a specific format for a person's name. Write a program that reads a person's name in the following format:
firstName middleName lastName (in one line)
and outputs the person's name in the following format:
lastName, firstInitial.middleInitial.
Ex: If the input is:

[SOLVED] Many documents use a specific format for a person's name. Write a program that reads a person's name in the following format:
firstName middleName lastName (in one line)
and outputs the person's name in the following format:
lastName, firstInitial.middleInitial.
Ex: If the input is:
See Answers (1)

Accepted Answer

Using the knowledge in computational language in JAVA it is possible to write the code that write a program whose input is: firstName middleName lastName, and whose output is: lastName, firstName middleInitial.Writting the code:import java.util.Scanner;import java.lang.*;public class LabProgram{public static void main(String[] args) {String name;String lastName="";String firstName="";char firstInitial=' ',middleInitial=' ';int counter = 0;Scanner input = new Scanner(System.in);name = input.nextLine(); //read full name with spacesint i;for(i = name.length()-1;i>=0;i--){if(name.charAt(i)==' '){lastName = name.substring(i+1,name.length()); // find last namebreak;}}for(i = 0;i<name.length()-1;i++){if(name.charAt(i)==' '){firstName = name.substring(0, i); // find firstNamebreak;}}for(i = 0 ;i<name.length();i++){if(name.charAt(i)==' '){counter++; //count entered names(first,middle,last or first last only)}}if(counter == 2){for(i = 0 ;i<name.length();i++){if(Character.toUpperCase(name.charAt(i)) == ' '){middleInitial = Character.toUpperCase(name.charAt(i+1));//find the middle name initial characterbreak;}}}firstInitial = Character.toUpperCase(name.charAt(0)); //the first name initial characterif(counter == 2){System.out.print(lastName+", "+firstName+" "+middleInitial+".");}else{System.out.print(lastName+", "+firstName);}}}See more about JAVA at brainly.com/question/12975450#SPJ1

Related Question in Computers and Technology