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 test {
  9. public static void main(String args[]) {
  10. String text = "Hello World!"; //Change the string to "Hello there!"
  11. int wordLengthCount [] = new int [20];
  12. String wordCountText = "";
  13.  
  14. String sentence[] = text.split("[,\\-:\\?\\!\\ ]");
  15.  
  16. for (int i = 0; i < sentence.length; i++)
  17. {
  18. wordLengthCount[sentence[i].length()]++;
  19. }
  20.  
  21. for(int wordLength=0; wordLength<wordLengthCount.length; wordLength++)
  22. {
  23. if (wordLengthCount[wordLength] != 0){
  24. wordCountText += wordLengthCount[wordLength] + " with length of " + wordLength + "\n";
  25. }
  26. }
  27. System.out.println(wordCountText);
  28. }
  29. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
2 with length of 5