fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11.  
  12. public static int wordCount(String str, int minLength) {
  13. int count = 0;
  14. for (int i = 0, wordLength = 0; i < str.length() + 1; i++) {
  15. if (i == str.length() || !Character.isLetter(str.charAt(i))) {
  16. if (wordLength >= minLength) {
  17. count++;
  18. }
  19. wordLength = 0;
  20. } else {
  21. wordLength++;
  22. }
  23. }
  24. return count;
  25. }
  26.  
  27. public static void main (String[] args) throws java.lang.Exception
  28. {
  29. System.out.println(wordCount("quick, brown fox jumps over? the.. lazy, dog!!!", 5));
  30. }
  31. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
3