I need to use a method to find out the last name of any given name - meaning given any full name as a parameter the method should return the last name.
Here is the code that I have written but which will not compile. Need help! Thanks in advance
class LastName {
public static void main(String[] args) {
getlastName(" ");
System.out.println();
}
public static String getlastName(String lastName) {
System.out.println("Enter your full name: ");
int firstSpace = fullName.indexOf(" ");
int middleSpace = fullName.middleIndexOf(" ");
lastName = fullName.substring(firstSpace,middleSpace);
return lastName;
}
}
.