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) );
}
}