// This program will scramble the value of the "word" variable
// Mr. Merlis | March 23, 2006
import java.util.Random;
public class StringTest
{
public static void main(String[] args)
{
String word = "lefty";
System.out.println("Your word is: " + word);
char[] letters = new char[word.length()];
Random rand = new Random();
int ranPos = 0;
for(int i = 0; i < word.length(); i++)
{
letters[i] = '*';
}
for(int j = 0; j < word.length(); j++)
{
do
{
ranPos = rand.nextInt(letters.length);
}while(letters[ranPos] != '*');
letters[ranPos] = word.charAt(j); // returns the letter in the jth position
}
String scrambledWord = new String(letters);
System.out.println("Scrambled it is: " + scrambledWord);
}
}