4. Write a program in Java to accept a name containing three words and display the
surname first, followed by the first and middle names.
Sample Input: MOHANDAS KARAMCHAND GANDHI
Sample output: GANDHI MOHANDAS KARAMCHAND
Share
4. Write a program in Java to accept a name containing three words and display the
surname first, followed by the first and middle names.
Sample Input: MOHANDAS KARAMCHAND GANDHI
Sample output: GANDHI MOHANDAS KARAMCHAND
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
Sample Input : Mohandas Karamchand Gandhi
Sample Output : Gandhi Mohandas Karamchand
Hint : Here , the last word of the name is placed first and the first word of the name is placed in the middle.
The answer is given in the image: