What is the easiest way to shuffle the letters of a word which is in an array? I have some words in an array and I choose randomly a word but I also want to shuffle the letters of it.
public static void main (String[] args ) {
String [] animals = { "Dog" , "Cat" , "Dino" } ;
Random random = new Random();
String word = animals [random.nextInt(animals.length)];
System.out.println ( word ) ;
//I Simply want to shuffle the letters of word
}
I am not supposed to use that List thing. I've come up with something like this but with this code it prints random letters it doesn't shuffle. Maybe I can code something like do not print if that letter already printed?
//GET RANDOM LETTER
for (int i = 0; i< word.length(); i++ ) {
char c = (word.charAt(random.nextInt(word.length())));
System.out.print(c); }
}