-4

I'm attempting to change the order of any given name and get an output of ("LastName, FirstName") by only using one string variable.

For example, if entered by the user as Winston Church it would print out

System.out.println("Church,Winston");

How would you combine the Full Name of the user into one or simply just use one string variable for the input? I don't wish to split it but rather combine it.

1 Answers1

1

Will this work for you?

public class NameModifier {


   public static void main(String []args) {
      String unmodified_full_name = "FirstName LastName";
      String[] full_name_array = unmodified_full_name.split(" ", 2);
      System.out.println(full_name_array[1] +   "," + full_name_array[0]);
   }
}
Danny.j
  • 29
  • 4