Guest User

Untitled

a guest
Jan 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.awt.*;
  4. class MySt {
  5. private String m_str;
  6. public MySt(String s) {
  7. this.m_str = s;
  8. }
  9. public String getStr() {
  10. return m_str;
  11. }
  12. public String getReverse() {
  13. String reverse = new StringBuffer(this.m_str).reverse().toString();
  14. return reverse;
  15. }
  16. public void kolvo (char a) {
  17. int o = 0;
  18. String [] p = this.m_str.split("");
  19. for(int i = 0; i <m_str.length();i++)
  20. if (a == this.m_str.charAt(i))
  21. o++;
  22. System.out.println("колличество совпадений :"+o);
  23. }
  24. static void fill (HashMap<String, Integer> dictionary, String source) {
  25. String[] words = source.split("[, .;?!:]");
  26.  
  27. for (String word : words)
  28. if (!word.isEmpty())
  29. if (!dictionary.containsKey(word))
  30. dictionary.put(word, 1); //
  31. else
  32. dictionary.put(word, dictionary.get(word) + 1);
  33. }
  34. static boolean validBrack(String s) {
  35. String reg = "{|}|(|)|[|]";
  36. Pattern p = Pattern.compile(reg);
  37. Matcher m = p.matcher(reg);
  38. boolean b = m.matches();
  39. if(b) return true;
  40. else return false;
  41. }
  42. public static void main(String [] args) {
  43. /*char p = 'm';
  44. MySt s = new MySt("qwertyuiopasdfghjklzxcvbnmmmmm");
  45. System.out.println(s.getReverse());
  46. s.kolvo(p);
  47. HashMap<String, Integer> dictionary = new HashMap<String, Integer>();
  48. String sourceOfWords = "haha haha lol LOL привет ;; как дела дела дела как дела дела дела hello собака собака каталась";
  49. String newStr = sourceOfWords.toLowerCase();
  50. fill (dictionary, newStr);
  51. for (String key : dictionary.keySet())
  52. System.out.println (key + ": " + dictionary.get(key));*/
  53. System.out.println(validBrack("{}{"));
  54. }
  55. }
Add Comment
Please, Sign In to add comment