189k views
1 vote
Write a method called justFirstAndLast that takes a single String name and returns a new String that is only the first and last name.

You may get a name with a middle name or multiple middle names but you should ignore those.


You can assume that there will be at least two names in the given String.

Java

public String justFirstAndLast(String name)

{

}

1 Answer

5 votes

Answer:

Answer is in the attached screenshot.

Step-by-step explanation:

Using regex to split a given input string via whitespace, then returns the first and last element of the array.

Write a method called justFirstAndLast that takes a single String name and returns-example-1
User MatthieuP
by
6.3k points