I want to generate a random and scrambled word from a vector. At the moment it is already generating a random but not scrambled word. I created a method called scramble where the words will be shuffled but I do not know I am not able to call on the main.
Current code:
import java.util.Random;
import java.util.Scanner;
public class findthewordgame {
public static void arrayword () {
String[] wordgame = new String[5];
wordgame[0] = "TEA";
wordgame[1]= "COFFE";
wordgame[2]= "BOAT";
wordgame[3]="SEA";
wordgame[4]="SUN";
int idx = new Random().nextInt(wordgame.length);
String random = (wordgame[idx]);
System.out.println(wordgame[idx]);
}
public static String scramble(Random random, String inputString )
{
// Convert your string into a simple char array:
char a[] = inputString.toCharArray();
// Scramble the letters using the standard Fisher-Yates shuffle,
for( int i=0 ; i<a.length ; i++ )
{
int j = random.nextInt(a.length);
// Swap letters
char temp = a[i]; a[i] = a[j]; a[j] = temp;
}
return new String( a );
}
public static void main (String[] args){
arrayword();
}
}