Results 1 to 6 of 6
  1. #1
    wethekings is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Talking Jumble Multiple Words

    Hi, I've kinda hit a snag at this.
    Ive written my code to jumble a word, but i need it to be able to jumble multiple words, without mixing them together.
    What i mean is like say i input: "readers digest"
    i would like it to produce something like: "esearrd tegsdi"
    instead of what it now produces as something like "reedraetssi dg"


    Java Code:
    /**
     *
     * @author Kevin Hohl
     */
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Scanner;
    
    public class WordShuffler {
    
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            String word;
            List listA = new ArrayList();
            int yes;
            final int SENTINEL = -1;
            System.out.println("Enter a word to be shuffled: "); 
            word = input.nextLine();
            word = word.toLowerCase();
            for (int i = 0; i < word.length(); i++){
            listA.add(word.charAt(i));
            }
            System.out.println("Jumbled word: " + shuffler(listA));
            do {
            System.out.println("Shuffle again?(1 to shuffle, -1 to quit)");
            yes = input.nextInt();
            System.out.println("Jumbled word: " + shuffler(listA));
            } while (yes != SENTINEL);
        }
        public static String shuffler(List a) {
            String wrdo = "";
            Collections.shuffle(a);
            for (int j=0; j < a.size(); j++) {
                wrdo += a.get(j);            
            }
        return(wrdo);
        }
    }
    any help with this would be very much appreciated, thank you :)

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    12

    Default

    if you're familiar with regexes, you can use the split() method of the String class. if not, you can try out the StringTokenizer class.

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    11

    Default

    i suggest breaking you original string into string arrays. and break down your class to use methods.
    Java Code:
    public class MultiWordShuffler {
    
        public static void main(String[] args){
          String s = "Reader Digest";
          String[] stringArray = ... // split s into arrays.
          
          for(int i=0; ... ){
            stringArray[i] = wordShuffler(stringArray[i]);
          }
    
          // combine stringArray back into one string.
        }
        
        public static String wordShuffler(String s){
        }
        
        public static String shuffler(List a){
        }
    }
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  4. #4
    wethekings is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default Woo finish

    Thanks. I finally figured out how to do it.
    Last edited by wethekings; 02-20-2009 at 09:51 AM.

  5. #5
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    11

    Default

    Please go to the top of the page, then click Thread Tools --> Mark This Thread As Solved.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  6. #6
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    11

    Default

    Mu sugg is Regular Expression
    Mak
    (Living @ Virtual World)

Similar Threads

  1. Money to Words
    By javanewbie in forum New To Java
    Replies: 2
    Last Post: 06-30-2008, 04:27 AM
  2. Scrambling Words
    By Shadow22202 in forum New To Java
    Replies: 9
    Last Post: 04-30-2008, 03:51 AM
  3. help w words
    By Gilgamesh in forum New To Java
    Replies: 5
    Last Post: 11-21-2007, 06:15 PM
  4. Jumble 1.0.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-18-2007, 05:50 PM
  5. Aspose.Words for Java - 2.1.0.0
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-24-2007, 10:08 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
  •