fork download
  1. import java.util.*;
  2.  
  3. public class Words {
  4.  
  5. public String countWords(List<String> lines) {
  6. StringBuilder result = new StringBuilder();
  7.  
  8. HashMap<String, Integer> wordsCount = new HashMap<>();
  9. for (String line : lines)
  10. {
  11. line=line.toLowerCase(Locale.ROOT);
  12. line = line.replaceAll("[^\\p{L}\\p{Nd}]+", " ");
  13. String[] words = line.split(" ");
  14. for (String word: words) {
  15. if( wordsCount.containsKey(word)){
  16. wordsCount.put(word, wordsCount.get(word)+1 );
  17. }else{
  18. wordsCount.put(word, 1);
  19. }
  20. }
  21. TreeMap<String, Integer> sortedMap = new TreeMap<>(wordsCount);
  22. for (Map.Entry<String, Integer> entry :sortedMap.entrySet() ) {
  23. if ( (entry.getValue()>9) && (entry.getKey().length()>3 ) ){
  24. result.append(entry.getKey() + " - " + entry.getValue() + "\r\n");
  25. }
  26. }
  27. }
  28. return (result.toString());
  29. }
  30.  
  31. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class Words is public, should be declared in a file named Words.java
public class Words {
       ^
1 error
stdout
Standard output is empty