Results 1 to 6 of 6
  1. #1
    SIAST is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default Help with scrambling a word

    Hi,

    I am new to learning Java and am working on an assignment and am having a bit of difficulty with one part of it. I am to develop a program where a word is entered, mixed up, and then displayed for the next person to guess. I am having difficulty in mixing the word up. Please help.
    Below were the instructions I was given.

    "The word provided by the first player needs to be mixed up. This can be accomplished by swapping two letters in the word twenty times. Randomly select two positions in the String using the Math.random method.

    You can swap the the letters using substring and charAt. Build a new String by concatenating the following pieces:
    The first part of the String up to the first position (using substring)
    Character at second position (using charAt)
    The part of the String between first and second position
    Character at first position
    The remainder of the String after second position"

  2. #2
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: Help with scrambling a word

    The best hint I could give you without giving to much of it away, would be to use something like:
    Java Code:
    char[] wordArray = word.toCharArray();
    This will transfer you String word, into a character array. You can then access the first character in the array using:
    Java Code:
    wordArray[0];
    It acts just like a normal array would. You can also use the .length() method on it to find the size.


    Hope that helps.
    Catching exceptions is for communists

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Help with scrambling a word

    Quote Originally Posted by penguinCoder View Post
    The best hint I could give you without giving to much of it away, would be to use something like:
    Java Code:
    char[] wordArray = word.toCharArray();
    This will transfer you String word, into a character array. You can then access the first character in the array using:
    Java Code:
    wordArray[0];
    It acts just like a normal array would. You can also use the .length() method on it to find the size.


    Hope that helps.
    That doesn't help a poster whose assignment clearly states
    Quote Originally Posted by SIAST View Post
    You can swap the the letters using substring and charAt.
    Additionally
    -- what's a 'normal array' -- or by inference, what makes an array abnormal?
    -- An array doesn't have a length() method.

    Please help us maintain the quality of responses on this forum by replying only to questions that are well within your comfort zone.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Help with scrambling a word

    @SIAST: You need to show us what you've tried and report any errors or incorrect results that are troubling you in order to get targeted help. As it presently stands, your post is what we here call a 'homework dump' -- and this is a forum, not a homework service.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with scrambling a word

    penguinCoder's post has been deleted for use of inappropriate language, and he has been banned for 3 days for the same.

    Please, let's at least act like adults in this forum. We have high school students who are active on this site.

  6. #6
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default Re: Help with scrambling a word

    Those directions are kind of confusing to me. What I would suggest you do is get a pen and paper and think of a single world. Write it down, and then re arrange it on the paper how you want it to be in the code. Then just write your code to work for that one word, hopefully after you get that done you will be able to make it work for all words without too much trouble.
    Of course if you run it to trouble just come back with whatever error you are getting.

Similar Threads

  1. how to reverse word by word?
    By yamicaitsith in forum New To Java
    Replies: 13
    Last Post: 09-16-2012, 11:30 PM
  2. Replies: 3
    Last Post: 08-30-2011, 04:44 PM
  3. [SOLVED] Help With Word Scrambling Application
    By MK12 in forum New To Java
    Replies: 14
    Last Post: 02-07-2009, 09:26 PM
  4. Word OLE
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-25-2008, 02:33 PM
  5. Scrambling Words
    By Shadow22202 in forum New To Java
    Replies: 9
    Last Post: 04-30-2008, 03:51 AM

Tags for this Thread

Posting Permissions

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