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 2 of 2

Thread: English to L33T Translator

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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)


    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 !


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,268
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: English to L33T Translator

    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” (
    Make a while loop containing the code to read and translate and print inside it.
    Exit the loop with a break statement when the user enters STOP.

Similar Threads

  1. need details on Implementing Dictionary Filters for English words
    By madcrazyboys in forum Java Theory & Questions
    Replies: 2
    Last Post: May 6th, 2011, 01:53 PM
  2. PigLatin translator help
    By Rusak in forum What's Wrong With My Code?
    Replies: 10
    Last Post: April 6th, 2011, 08:53 AM
  3. Translate Java Code Into English
    By drkossa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2009, 02:52 PM
  4. Help with Pig Latin Translator...
    By jchan in forum AWT / Java Swing
    Replies: 3
    Last Post: September 28th, 2009, 03:54 PM
  5. Pig Latin Translator
    By BMN901 in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: June 17th, 2009, 04:31 AM