scramble()

Platform:  Java
Published  Apr 08, 2009
Updated  Apr 08, 2009
This is a method for Java that scrambles up a string. You just add it to your class and call it by doing scramble(string).

Also, make sure at the top of the project you import java.util.Random;


Examples:

* variable = scramble(variable);
* System.out.println(scramble("elephant")); public static String scramble(String word) {
String newword = "";
int rndnum;
Random randGen = new Random();
boolean letter[] = new boolean[word.length()];
do {
rndnum = randGen.nextInt(word.length());
if (letter[rndnum] == false) {
newword = newword + word.charAt(rndnum);
letter[rndnum] = true;
}
} while (newword.length() < word.length());
return newword;
}

Comments

Sign in to comment.
Joshuaxiong1   -  Nov 16, 2009
lol first comment
Don't know what to do with it
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.