title: Find the smallest word in a string in Java
body: <p>I'm trying to find the smallest word in a user entered string. This is what I have so far:</p>
  
  <pre><code>import java.util.*;
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
  
      String myText = sc.next();
      String[] myWords = myText.split(" ");
      int shortestLength,shortestLocation;
  
      shortestLength=(myWords[0]).length();
  
      shortestLocation=0;
  
      for (int i=1;i&lt;myWords.length;i++) {
          if ((myWords[i]).length() &lt; shortestLength) {
              shortestLength=(myWords[i]).length();
              shortestLocation=i;
          }
      }
      System.out.println(myWords[shortestLocation]);
  }
  </code></pre>
  
  <p>If I entered <code>"SMALLEST WORD SHOULD BE A"</code>, the output should be <code>A</code> but it just gives me the first word of the string. Any ideas?</p>