Question

Language is Java Name format Many documents use a specific format for a person's name. Write...

Language is Java

Name format

Many documents use a specific format for a person's name. Write a program whose input is:

firstName middleName lastName

and whose output is:

lastName, firstInitial.middleInitial.

Ex: If the input is:

Pat Silly Doe

the output is:

Doe, P.S.

If the input has the form:

firstName lastName

the output is:

lastName, firstInitial.

Ex: If the input is:

Julia Clark

the output is:

Clark, J.

Homework Answers

Answer #1
import java.util.Scanner;

class LabProgram {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] words = s.split(" ");
        String firstName = words[0];
        String middleName = words[1];
        if (words.length == 2)
            System.out.println(middleName + ", " + firstName.charAt(0) + ".");
        else {
            String lastName = words[2];
            System.out.println(lastName + ", " + firstName.charAt(0) + "." + middleName.charAt(0) + ".");
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write an assembly language program that prints your full name on the screen. Use .ASII pseudo-op...
Write an assembly language program that prints your full name on the screen. Use .ASII pseudo-op to store the characters at the top of your program Use BR to branch around the characters and use STRO to output your name. Comment each line except STOP and .END. Cut and paste the Assembler Listing into your document Paste a screen shot of the Output area of the Pep8 program Please use the name "Levin Fi" Assembler Listing Screen Shot of the...
in java A way to measure the amount of energy spent during an exercise is to...
in java A way to measure the amount of energy spent during an exercise is to use metabolic equivalents (MET). The formula to use is: METs x 3.5 x (weight in kg ) / 200 = calories burned per minute . For example, say you weigh 160 pounds (approximately 73 kg) and you play singles tennis, which has a MET value of 8. The formula would work as follows: 8 x 3.5 x 73 / 200 = 10.2 calories per...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields and appropriate types and permissions diceType numSides sideUp The class should have A 0 argument (default) constructor default values are diceType: d6, numSides: 6, sideUp: randomValue 1 argument constructor for the number of sides default values are diceType: d{numSides}, sideUp: randomValue 2 argument constructor for the number of sides and the diceType appropriate accessors and mutators *theoretical question: can you change the number of...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
Need in C language also need full documentation/explanation of each line A student has established the...
Need in C language also need full documentation/explanation of each line A student has established the following monthly budget: Budget Categories Budgeted amount ----------------------------------------------------- Housing $ 580.00 Utilities $ 150.00 Household Expenses     $ 65.00 Transportation $ 50.00 Food $ 250.00 Medical $ 30.00 Insurance $ 100.00 Entertainment $ 150.00 Clothing $ 75.00 Miscellaneous $ 50.00 ---------------------------------------------------- Write a program that declares a MonthlyBudget structure designed with member variables to hold each of these expense categories. The program should define...
In narrative essay format, I want you to address a business/organization case study using multiple concepts...
In narrative essay format, I want you to address a business/organization case study using multiple concepts from class. The case question and case text begin on page 5 of this document. You need to demonstrate their best understanding of management and organizational behavior theory, and the application of those ideas to improve the understanding of various issues. You need to clearly identify at least 3 distinct, substantive issues. For each issue you need to 1), identify evidence from the case...
PHP, HTML5 Accounting Import The Mammoth Island Tourism Company is undergoing a project to digitize a...
PHP, HTML5 Accounting Import The Mammoth Island Tourism Company is undergoing a project to digitize a large quantity of paper documents, sales records going back 100 years. They’ve already commissioned a company to digitize the documents into a text format, but now they require an application to extract a small amount of useful information from the documents. Unfortunately, their accounting format changed several times over the course of business, so the application must be intelligent enough to find the data....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT