title: How to show sentence word by word in a separate line
body: <p>The sentence String is expected to be a bunch of words separated by spaces, e.g. “Now is the time”.
  showWords job is to output the words of the sentence one per line.</p>
  
  <p>It is my homework, and I am trying, as you can see from the code below. I can not figure out how to and which loop to use to output word by word... please help.</p>
  
  <pre><code>import java.util.Scanner;
  
  
  public class test {
      public static void main(String[] args) {
          Scanner in = new Scanner(System.in);
  
          System.out.println("Enter the sentence");
          String sentence = in.nextLine();
  
          showWords(sentence);
  }
  
      public static void showWords(String sentence) {
          int space = sentence.indexOf(" ");
          sentence = sentence.substring(0,space) + "\n" + sentence.substring(space+1);
          System.out.println(sentence);
      }
  
  }
  </code></pre>