Ask Question
6 May, 20:12

Write a method named lastFirst that accepts a string as its parameter representing a person's first and last name. The method should return the person's last name followed by the first initial and a period. For example, the call lastFirst ("Marla Singer") should return "Singer, M.". You may assume that the string passed consists of exactly two words separated by a single space.

+2
Answers (1)
  1. 6 May, 23:34
    0
    I'm going to assume this is Java, because you said "method" meaning it will be some sort of object oriented language, and Java's really common. Here would be the full program, but you can just take the method out isolated if you need it.

    package lastname;

    public class LastName {

    public static void main (String[] args) {

    / / Example usage:

    String name = LastName. lastName ("Garrett Acord");

    System. out. println (name);

    / / Output: Acord G.

    }

    public static String lastName (String fullName)

    {

    String[] splitName = fullName. split (" ");

    return String. format ("%s %s.", splitName[1], splitName[0]. substring (0,1));

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a method named lastFirst that accepts a string as its parameter representing a person's first and last name. The method should return ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers