title: Java: taking only the first word of a user input string
body: <p>Homework question that I've been having a little trouble with...</p>
  
  <p>I need to have a user input string as a product category. If the user inputs more than one word, I need to take only the first word typed. </p>
  
  <p>Stipulation: I cannot use 'if' statements. </p>
  
  <p>Here's what I have so far, but it fails if only one word is typed.</p>
  
  <pre><code>Scanner scan = new Scanner (System.in);
  System.out.println ("Enter a noun that classifies the"
                      + " type of your product:");
  
  String noun = scan.nextLine();
  int n = noun.indexOf(" ");
  String inputnoun = noun.substring(0,n);
  </code></pre>