title: How to find the length of the last word in java?
body: <p>I want to find the length of the last word to initially find the length of the second word in the phrase. here's my plan, If I find the length of the last phrase then in the for loop if I subtract x, it should give me the length of the second word always. This has to be done using for loop and a scanner, where the user inputs any phrase.
  Basically, I need to know how to find the length of the last phrase. Thats what I need to know only.</p>
  
  <p>here's my code:</p>
  
  <pre><code>else if (option == 2){
      int counter = 0 ;
      for (int x = 0; x &lt; phrase.length() - x; x++){ 
          //in the "int x = 0" i need to put the length of the last word 
          // in a phrase 
          char n = phrase.charAt(x);
          if (n == x);
          counter++;
      }
      System.out.print("Second word has "+counter+" letters");
  }
  </code></pre>