How do I extract the middle name from the full name?
<p>My program is supposed to extract the middle name of a full name. I have another method and I can't call it properly in my main method. The code is working if it is in the main method, but it doesn't work in the other method; I assume the problem is when calling the method. I am using Eclipse.</p>

<pre><code>import java.util.Scanner;
public class MiddleNames {
  public static void main(String[] args) {
    getMiddleName(" ");
    System.out.println();
  }

  public static String getMiddleName(String middleName) {
    Scanner input = new Scanner(System.in);
    System.out.println("Enter your full name: ");
    String fullName = input.nextLine();
    int firstSpace = fullName.indexOf(" ");
    int lastSpace = fullName.lastIndexOf(" ");
    middleName = fullName.substring(firstSpace,lastSpace);
    return middleName;  
  } 
}
</code></pre>
