How to convert "7H15 M3554G3" into words in Java

1 Answer

0 votes
// 7H15 M3554G3 is written in leet speak, where numbers resemble letters. 
// place each leetspeak character with its matching letter 
// (7 -> T, 1 -> I, 5 -> S, 3 -> E) and build a new string
// 7H15 -> THIS | M3554G3 -> MESSAGE
 
// Your brain can interpret distorted or number‑substituted letters 
// surprisingly well because it recognizes the overall word 
// shapes and patterns, not just individual characters.

import java.util.HashMap;

public class LeetToText {

    public static String leetToText(String s) {
        HashMap<Character, Character> map = new HashMap<>();
        map.put('7', 'T');
        map.put('1', 'I');
        map.put('5', 'S');
        map.put('3', 'E');
        map.put('4', 'A');
        map.put('0', 'O');

        StringBuilder out = new StringBuilder(s.length());

        for (char c : s.toCharArray()) {
            if (map.containsKey(c))
                out.append(map.get(c));
            else
                out.append(c);  // keep letters like H, M, G
        }

        return out.toString();
    }

    public static void main(String[] args) {
        String input = "7H15 M3554G3";

        System.out.println(leetToText(input));
    }
}


/*
run:

THIS MESSAGE

*/

 



answered 2 hours ago by avibootz
edited 1 hour ago by avibootz
...