English to L33T Translator
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)
Code :
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;
}
if a character (including other letters or numbers, space, etc.) does not have an alternative in the table, leave it as is
Where am I going wrong?
Appreciate the help
Thanks !
Re: English to L33T Translator
Is this the same problem as this:
http://www.javaprogrammingforums.com...ranslator.html
Why not continue on the first thread?
Quote:
Where am I going wrong?
Please show what the program is currently doing and explain what is wrong with it and show what it should do.
Re: English to L33T Translator
You told me to post a new thread, so I did.
As I said, the goal is to successfully translate a sentence (which will be taken as input from the user) from English to L33T based on the arrays provided. Currently, that translation is not working - I am getting the wrong output characters.
Re: English to L33T Translator
Quote:
I am getting the wrong output characters.
Please show what the program is currently doing and explain what is wrong with it and show what it should do.
Re: English to L33T Translator
Here is a screenshot of the output:
Image - TinyPic - Free Image Hosting, Photo Sharing & Video Hosting
I should be getting "#3110" for the output (the LEET translation for Enlgish)
Why is this happening and how do I fix it.
Remember that if there is no translation in the key, we leave the letter as is
Re: English to L33T Translator
Try debugging the code by adding printlns that show what is happening.
For simplicity, give the program one or two letters as input. Print out everything that happens in the translation to see where the code is going wrong.
For example if you give it "H" you should get out a "#"?
"HE" should give "#3"
Re: English to L33T Translator
I don't know if this crosses the line in to spoon feeding, but it looks like he just forgot to put "D" in to his english array. He has the whole idea right, he just made a typo.
Re: English to L33T Translator
@DougFane Do you know the definition of the L33T language? What letters are translated and what letters stay the same.
The OP should certainly line up the two arrays and see if the corresponding letters match as expected.
Re: English to L33T Translator
Where are you? After PMing me 3 times to give you help, you seem to have lost interest in working on a solution.
Re: English to L33T Translator
No I just saw that there was a l33t string of "|)" that did not make sense for any english string but "D" and all of his outputs were off by one, which could indicate that there is an element missing from the array.