Okay this is my assignment question:
Write a program that accept the format last name, first name and print out first name, last name
Thats what I did:
import java.util.Scanner;
public class Name
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter your name");
String name = input.nextLine();
System.out.println( "\nReversed name:" );
String[] Name = name.split( "," );
for ( String n: Name)
{
System.out.println(n);
}
}
}
*****************************************************
Output
Enter your name
Sam, Adams
Reversed name:
Sam
Adams
******************************************************
My question is How can I make my last name goes beside my first name not below it and also I want to keep the comma in the reversed name .
I would appreciate your help and sorry if this is a simple question