In Java please. Only aswer the code where it says "/* Your code goes here */". Write a method lastNameFirst that takes a string containing a name such as "Harry Smith" or "Mary Jane Lee", and that returns the string with the last name first, such as "Smith, Harry" or "Lee, Mary Jane". import java.util.Scanner; public class Names { /** Changes a name so that the last name comes first. If name has no spaces, it is returned without change. @param name a name such as "Mary Jane Lee" @return the reversed name, such as "Lee, Mary Jane". */ public static String lastNameFirst(String name) { /* Your code goes here */ } public static void main(String[] args) { Scanner in = new Scanner(System.in); String name = in.nextLine(); System.out.println(lastNameFirst(name)); } }
In Java please. Only aswer the code where it says "/* Your code goes here */".
Write a method lastNameFirst that takes a string containing a name such as "Harry Smith" or "Mary Jane Lee", and that returns the string with the last name first, such as "Smith, Harry" or "Lee, Mary Jane".
import java.util.Scanner;
public class Names
{
/**
Changes a name so that the last name comes first.
If name has no spaces, it is returned without change.
@param name a name such as "Mary Jane Lee"
@return the reversed name, such as "Lee, Mary Jane".
*/
public static String lastNameFirst(String name)
{
/* Your code goes here */
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String name = in.nextLine();
System.out.println(lastNameFirst(name));
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
How do I fix this?
![1: Compare output
Input
Your output
X 2: Compare output
Input
Output is nearly correct, but whitespace differs. See highlights below.
Your output
Expected output
X 3: Compare output
Input
Your output
Expected output
Harry Smith
✓ 4: Compare output
Smith, Harry
Output is nearly correct, but whitespace differs. See highlights below.
Innut
Mary Jane Lee
Lee, MaryJane
Lee, Mary Jane
Robert X. Cringely
Cringely, RobertX.
Cringely, Robert X.
Pocahontas
Special character legend
Special character legend](https://content.bartleby.com/qna-images/question/b4d4e6a3-fd83-4270-b000-89a89a72868b/fb039bd9-be3d-4a93-9c6f-964ba49e14c6/kzclzui_thumbnail.png)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)