daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //frequency dic, OOP-style
  2. //enter english string
  3. //out: гласные: a встречается n раз, и т.д.
  4. import java.util.*;
  5. public class StringAnalyzer {
  6.     public static String count (String foo) {
  7.         TreeMap<Character, Integer  > tree = new TreeMap<Character, Integer>();
  8.         char tmp;
  9.         int bar;
  10.         StringBuffer result = new StringBuffer();
  11.         for (int i=0; i<foo.length(); i++) {
  12.             tmp = Character.toLowerCase(foo.charAt(i));
  13.             if (tmp=='e'||tmp=='y'||tmp=='u'||tmp=='i'||tmp=='o'||tmp=='a') {
  14.                 if(tree.get(tmp) == null) {
  15.                     tree.put(tmp,1);
  16.                 } else {
  17.                     tree.put(tmp,tree.get(tmp)+1);
  18.                 }
  19.             }
  20.         }
  21.         Iterator it = tree.entrySet().iterator();
  22.         while (it.hasNext()) {
  23.             Map.Entry en = (Map.Entry) it.next();
  24.             result.append("(" + en.getKey() + " => " + en.getValue() + ")\n");
  25.             //( "(" + en.getKey() + " => " + en.getValue() + ")\n" );
  26.         }
  27.         return result.toString();
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top