fork download
  1. import java.util.regex.*;
  2.  
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String t = "recede";
  9. System.out.println(encode(t));
  10. //System.out.println(Kata.encode(t));
  11. }
  12.  
  13. public static String encode(String word){
  14. StringBuilder result = new StringBuilder();
  15. char[] arr = word.toCharArray();
  16. for (char c : arr) {
  17. if (word.toUpperCase().chars().filter(ch -> ch == Character.toUpperCase(c)).count() > 1)
  18. result.append(")");
  19. else
  20. result.append("(");
  21. }
  22. return result.toString();
  23. }
  24. }
Success #stdin #stdout 0.1s 55456KB
stdin
Standard input is empty
stdout
()()()