Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problem with my code for a Leet Translator

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with my code for a Leet Translator

    Hi everyone! I am currently working for my assignment in java and it is a Leet Translator. My problem is when i enter the word "enter" the output is "\+", it must be "3\+3r"... So what do you think is the problem with my code? Please help me!!!

    My code is :
    import javax.swing.*;
     
    public class Leet{
     
    		String [] english = {"A","a","b","B","c","C","E","f","F","G","g","H","i",
    				     "I","J","j","K","k","M","m","N","n","O","o","q","Q",
    				     "s","S","t","T","W","w","y","Y","Z","z"};
     
    		String [] leet = {"4","@","6","8","(","[","3","ph","Ph","9","9","#","1",
    				  "|","]","]","<","<","^^","^^","\\","\\","0","0","k","K",
    				  "5","$","+","7","VV","vv","j","J","2","2"};
     
    	public static void main(String [] args){
    		Leet leet = new Leet();
    	}
     
    	public Leet(){
    		String inputSentence = JOptionPane.showInputDialog("Enter phrase:");
    		String output = "";
     
    		output = translate(inputSentence);
     
    		JOptionPane.showMessageDialog(null, output);
     
     
     
     
     
     
    	}
     
    	public String translate(String strTranslate){
    		String strTranslateCharacter = "", result = "";
    		for(int x = 0; x < strTranslate.length(); x++){
    			strTranslateCharacter = strTranslate.charAt(x)+"";
    			for(int y = 0; y < english.length; y++){
    				if(strTranslateCharacter.equals(english[y])){
    					result += leet[y];
    				}
    			}
    		}
     
    		return result;
    	}
    }
    Last edited by jps; September 8th, 2013 at 12:48 AM. Reason: fixed code tags (no spaces allowed)


  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Problem with my code for a Leet Translator

    I also found letter "d" & "l" would not appear as with "e" when i ran your code

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Problem with my code for a Leet Translator

    Add some printlns or watch the variables in a debugger to see where things go unexpected

    According to the given input/output it seems the code is not correctly translating the letter 'e' or the letter 'r'
    Try to verify this assumption with other input that includes these letters, and try to determine why this may happen
    There may be other characters that do not translate as well

Similar Threads

  1. English to L33T Translator
    By eeengenious in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 30th, 2012, 08:11 AM
  2. English to L33T Translator
    By eeengenious in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 28th, 2012, 07:19 AM
  3. Creating a slang translator
    By TFG in forum What's Wrong With My Code?
    Replies: 14
    Last Post: July 28th, 2011, 11:02 AM
  4. PigLatin translator help
    By Rusak in forum What's Wrong With My Code?
    Replies: 10
    Last Post: April 6th, 2011, 07:53 AM
  5. Pig Latin Translator
    By BMN901 in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: June 17th, 2009, 03:31 AM

Tags for this Thread