Hi! I hope some can help me. I'm learning java on my own. I want to be able to scramble sentences, but I want to assign each letter with another letter of my choice. For example: Unscramble these words. It then would read nseubcralm esteh dswor. Thanks in advance.
Scramble Words
Started by Elaine, Oct 10 2010 07:44 AM
1 reply to this topic
#1
Posted 10 October 2010 - 07:44 AM
|
|
|
#2
Posted 10 October 2010 - 08:02 AM
What I would do is:
[1]Split the string on every space using String.split(" ");
[2]loop trough every string in the array
[3]for each string (word), generate a random number between 0 and word.length();
[4]take the letter at the random position, and put it in a new string
[5]remove this letter from the word
[6]go to step 3
Tip, the StringBuilder class has a charAt(int index), and a deleteCharAt(int index) method.
[1]Split the string on every space using String.split(" ");
[2]loop trough every string in the array
[3]for each string (word), generate a random number between 0 and word.length();
[4]take the letter at the random position, and put it in a new string
[5]remove this letter from the word
[6]go to step 3
Tip, the StringBuilder class has a charAt(int index), and a deleteCharAt(int index) method.


Sign In
Create Account

Back to top









