title: Getting length of names in Java with nextLine()
body: <p>I am very new to Java. I'm in my first Java class and we are just working on the basics. I am supposed to write a program that prompts the user to enter their first, middle, and last name with spaces. Then display the length of the first name, the length of the middle name, the initials, and the full name in all upper case. Here is the class example </p>
  
  <p>Example Output:</p>
  
  <pre><code>Enter a first name middle name and surname
  Peggy Sue Palmer
  
  Length of your name: 16 characters
  
  Length of your middle name: 3 characters
  
  Your initials are PSP
  
  PEGGY SUE PALMER
  </code></pre>
  
  <p>I have worked on some code so far and I am able to get some of the output correctly but when I go to enter Peggy Sue Palmer I have to input the name one at a time with a space at the end and then press enter to input the next name. Also it displays the length of the middle initial as 4 instead of 3. I know that I can have the input all on one line by just having one input String name = input.nextLine(), which allows the input format I am looking for but if I do that I have no clue how to get the length of the middle name or the initials. Sorry this is a dumb question but this is my first Java class and we are just learning the basics. </p>
  
  <pre><code>package tracy2prog1;
  import java.util.Scanner;
  public class Tracy2prog1 {
  
  public static void main(String[] args) {
      //create new scanner class
      Scanner input = new Scanner(System.in);
      //prompt user to enter first middle and last name
      System.out.println("Please enter your first middle and last name with spaces between them");
      String firstname = input.nextLine();
      String middlename = input.nextLine();
      String lastname = input.nextLine();
      System.out.println(firstname.length() + middlename.length() + lastname.length());
      System.out.println("The length of your middle name is " + middlename.length() + " characters");
      System.out.println("Your initials are " + firstname.charAt(0) + middlename.charAt(0) +lastname.charAt(0));
      System.out.println(firstname.toUpperCase() + middlename.toUpperCase() + lastname.toUpperCase());
  
    }
  
   }
  </code></pre>
  
  <p>Here is the updated code that works, only issue is its not counting the spaces in the output of the full name to 16, I am getting 14. </p>
  
  <pre><code>package tracy2prog2;
  import java.util.Scanner;
  public class Tracy2prog2 {
  
  public static void main(String[] args) {
      //create new scanner class
              Scanner input = new Scanner(System.in);
              //prompt user to enter first middle and last name
              System.out.println("Please enter your first middle and last name with spaces between them");
              String firstname = input.next();
              String middlename = input.next();
              String lastname = input.next();
              System.out.print("Your name is ");
              System.out.println(firstname.length() + middlename.length() + lastname.length() + " characters");
              System.out.println("The length of your middle name is " + middlename.length() + " characters");
              System.out.println("Your initials are " + firstname.charAt(0) + middlename.charAt(0) +lastname.charAt(0));
              System.out.println(firstname.toUpperCase() + " " + middlename.toUpperCase() + " " + lastname.toUpperCase());
  
  
  }
  </code></pre>
  
  <p>}</p>