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.
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();
}
}
Comments
Leave a comment