Question: Please use JAVA Write a public static method named nameToInitials that will take a single argument of type String and will return a String. When

Please use JAVA
Write a public static method named nameToInitials that will take a single argument of type String and will return a String. When called, and passed a name, this method must compute and return a String value with the initials for the given name.
Here are some examples showing what the value returned by your nameToInitials method should be for different argument values:
nameToInitials("Bob Allen Smith") should return the String value "B. A. S."
nameToInitials("Bob Smith") should return the String value "B. S."
nameToInitials("Bob") should return the String value "B."
Note that the argument to this method may be a String containing just a first name (i.e. "Bob"), just first name and last name (i.e. "Bob Smith"), or the first name and middle name and last name (i.e. "Bob Allen Smith").
You must also write a small program in the main method that will:
prompt the user to enter a name
collect and store the user's input in a String variable
call the nameToInitials method, passing the user's input as an argument
store the value returned by the nameToInitials method in another String variable
Display the name and initials as shown in the examples below
Example 1
Enter name : Bob Allen Smith
Initials for Bob Allen Smith : B. A. S.
Example 2
Enter name : Bob Smith
Initials for Bob Smith : B. S.
Example 3
Enter name : Bob
Initials for Bob : B.
For the given inputs, make sure that your program output looks exactly like the example above (including spelling, capitalization, punctuation, spaces, and decimal points).
Hints and Helpful Info
The indexOf method can be very helpful for finding things like space characters in a String
Java has an overloaded indexOf method with takes an extra int argument indicating where to start a search in a String
Java also has an lastIndexOf method, which searches a String starting at the end.
The substring method can be very helpful for extracting one or more characters from a String
You may need to wrtie some to code to make decisions based on whether the input has one (just first), two (first and last), or three (first, middle, and last) names.
The number of spaces in the input can help you determine how many names are in the input.
It can be helpful to know and understand the difference between the Scanner methods next and nextLine
 Please use JAVA Write a public static method named nameToInitials that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!