Hi all,
Working on a simple english to L33T Translator (using the java.lang.String ), below is my code:
Basically what I'm trying to do is get an input sentence from a user, isolate that sentence character by character (with each character getting passed to the translate method), and making the swap by mapping equivalents from english to l33t data structures (currently not working as desired)
public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Please enter a sentence to translate to L33T: "); String sentence = scan.nextLine(); String result = ""; for (int i = 0; i < sentence.length(); i++) { result += translate(sentence.substring(i,i+1)); } System.out.println(result); } public static String translate (String str) { String result = ""; String[] english = {"A", "a", "B", "C", "E", "G", "g", "H", "I", "i", "L", "O", "R", "S", "T", "X", "Z"}; String[] leet = {"4" , "@", "8" , "(" , "|)", "3", "6", "9", "#" , "1", "!", "1", "0", "12" , "5", "7", "†", "x", "2"}; for (int i = 0; i < english.length; i++) { if (str.equalsIgnoreCase(english[i])){ result += leet[i]; } } return result; }
Coming from a c background, but how would you be able to receive one string at a
time, translate it, prints the translation to the screen, wait for the
next input until it gets the input string “STOP” (case sensitive), in which case it terminates without translating in JAVA?
Additionally, if a character (including other letters or numbers, space, etc.) does not have an alternative in the table, leave it as is
Appreciate the help !