Answer to Question #234214 in Java | JSP | JSF for Klevis Malaj

Question #234214

Write a program that reads a person's first and last names separated by a space, assuming the first and last names are both single words. Then the program outputs last name, first name. End with newline.


1
Expert's answer
2021-09-06T23:58:40-0400
import java.util.Scanner;


public class PersonFullName {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //reads a person's first and last names separated by a space
        System.out.print("Enter a person's first and last names separated by a space: ");
        String[] fullName=input.nextLine().split(" ");
        //output last name, first name. End with newline.
        System.out.println(fullName[1]+" "+fullName[0]);       
        // close Scanner
		input.close();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS