Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2011
    Posts
    13
    Rep Power
    0

    Default Enciphing Text based on a word

    So basically I'm trying to make a program where a user inputs a word and based on the alphabet and the amount of letters entered it will change the alphabet then output the word as the new alphabet

    E.G The user enters "Test" and the alphabet changes so that every letter is changed to say test

    original: a b c d e f g h i j k l m n o p q r s t u v w x y z - 26 letters
    new: t e s t t e s t t e s t t e s t t e s t t e s t t e - 26 letters

    Then when it outputs the Enciphered word it should read "Ttet"


    Here is what I've got so far, I've set the normal alphabet and I've tried testing to count how many letters the user inputs maybe if that's a way I can do it I'm not sure

    Java Code:
    import java.util.*;
    
    public class LetterConverter {
    
        final private  static String[] alphabet = {"a", "b", "c", "d", "e",
            "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", 
            "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    
        public static void main(String[] args) 
        {
            Scanner input = new Scanner(System.in);
            System.out.println("Enter Word:");
            String word = "";
            word = input.nextLine();
            int textLength = word.length();
            System.out.println("Number of letters:" +textLength);
        }
    
    }
    It's hard to explain but I'm just stuck at what I should be doing

  2. #2
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Enciphing Text based on a word

    Here is some general help, you are not lost in a programming sense, it looks like you are lost as far as the algorithm. If this solution eludes you in this manner it is usually a matter of your math or problem solving skills, so take some time to practice both. I'll get you pointed in the right direction:

    first look at how many times your word goes into 26. Then look at the remainder. You can the construct a string that is 26 characters long. for example if you word is 4 characters long it goes into 26 6 times. So if you concatenate your 4 letter word 6 time plus the first 2 indexes for the word you'll have your new alphabet. Then you can look at the index that is one less than the corresponding number of that letter. You do not even explicitly need an Array unless your assignment requires it. I would guess when you would get to that point you could figure on how to get your out put.

    hope this helps!

Similar Threads

  1. Text extraction from pdf word and excel
    By agastheswar in forum Advanced Java
    Replies: 1
    Last Post: 01-21-2012, 09:49 AM
  2. Replies: 3
    Last Post: 08-30-2011, 04:44 PM
  3. Get selected text from MS Word,browser,pdf file
    By binhdinh0708 in forum New To Java
    Replies: 2
    Last Post: 04-17-2011, 04:04 PM
  4. Replies: 3
    Last Post: 06-26-2010, 08:11 AM
  5. Importing text into a word document
    By Frys82 in forum AWT / Swing
    Replies: 5
    Last Post: 08-24-2009, 08:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •