title: Searching for the second word in a string
body: <p>I'm a newbie in java and I was doing this exercise, to search the second word in a string, for example, if a string is "I love java" the program should return "love". </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.util.*;
  
  // This program returns the second word of a string
  public class SecondWord{
      public static void main(String[]args){
          Scanner in = new Scanner(System.in);
          System.out.println("String: ");
          String x = in.nextLine();
          int pos = x.indexOf(" ");
          int pos1 = x.indexOf(" ", pos);
          String second = x.substring(pos, pos1);
          System.out.println(second);
      }
  }
  </code></pre>
  
  <p>It compiles, but it returns nothing. What's wrong?</p>