Ad
Strings
Data Types

Using Map and jdk8 streams :)

Code
Diff
  • import java.util.HashMap;
    import java.util.Map;
    import java.util.stream.Collectors;
    
    class Dislexifier
    {
      public static final Map<String, String> replaceMap;
    
        static {
            replaceMap = new HashMap<>();
            replaceMap.put("a","4");
            replaceMap.put("o", "0");
            replaceMap.put("e","3");
            replaceMap.put("i","1");
        }
    
        public static String theDislexifier(String str) {
            return str.chars().mapToObj(cp -> String.valueOf((char)cp))
                    .map(c -> replaceMap.getOrDefault(c.toLowerCase(),c))
                    .collect(Collectors.joining());
        }
    }
    
    • import java.util.HashMap;
    • import java.util.Map;
    • import java.util.stream.Collectors;
    • class Dislexifier
    • {
    • public static String theDislexifier(String str)
    • {
    • // TODO: Do your magic here
    • return str.replace("a","4").replace("A","4").replace("o","0").replace("O","0").replace("e","3").replace("E","3").replace("i","1").replace("I","1");
    • }
    • public static final Map<String, String> replaceMap;
    • static {
    • replaceMap = new HashMap<>();
    • replaceMap.put("a","4");
    • replaceMap.put("o", "0");
    • replaceMap.put("e","3");
    • replaceMap.put("i","1");
    • }
    • public static String theDislexifier(String str) {
    • return str.chars().mapToObj(cp -> String.valueOf((char)cp))
    • .map(c -> replaceMap.getOrDefault(c.toLowerCase(),c))
    • .collect(Collectors.joining());
    • }
    • }