Results 1 to 2 of 2
  1. #1
    greg677 is offline Member
    Join Date
    Apr 2010
    Posts
    7
    Rep Power
    0

    Default generate random letters inbetween a string

    i am trying to create a program with will encode a word into special characters by using the space_size variable for example:i enter the word bill and the space_size is 2, therefore the program will output (@b*^i^@l(!l however i am having problems outputting this at the moment the code is adding an integer at the end of the word like bill245 for example, how do i correct this so it display 2 random characters in between each letter. Thanks for the help.

    Java Code:
       for (int i=0; i < word.length(); i++)
          {
            char c = word.charAt(i);
            k = (int) word.length();
            int j = (int) c;
            System.out.println("ASCII of: "+ c +" = " + j);
            ascii_total = ascii_total + j;
          }
       char_total = char_total + k;
       space_size = ascii_total % char_total;
    
       System.out.println("Value length is: " + ascii_total);
       System.out.println("The word length is: " + char_total);
       System.out.println("The spacing size is: " + space_size);
    
       System.out.println("Please enter a sentence: ");
       sentence = keyboard.nextLine();
    
       for ( int l=1; l <= space_size; l++)
          {
             char d = sentence.charAt(space_size);
             double randomNumber = Math.random();
             double randomNumberSetup = (randomNumber * 26 + 'a');
             char randomCharacter = (char) randomNumberSetup;
             final_word = (randomCharacter + d + sentence);
             System.out.println("The secret word is: " + final_word);
          }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I'm not exactly comfortable with your question. Correct me if I'm wrong. You have a word with letters and you are encoding in a way that you want. Then what you want to do is, if the word contain both letters, as well digits then encoding only letters ?

Similar Threads

  1. Replies: 8
    Last Post: 04-19-2009, 05:50 PM
  2. Generate unique letters
    By bl00dr3d in forum New To Java
    Replies: 22
    Last Post: 04-10-2009, 02:44 PM
  3. Generate a random code 4 letters long
    By bl00dr3d in forum New To Java
    Replies: 9
    Last Post: 04-06-2009, 05:32 AM
  4. Trying to Generate Random number
    By PeterFeng in forum New To Java
    Replies: 10
    Last Post: 01-14-2009, 08:37 AM
  5. Generate a random number
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:23 AM

Posting Permissions

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