The 2 arrays would then be shuffled, and input would be needed to reorganize them?
I have 2 main questions regarding this, how would 1 'shuffle' an array, and how would you get the input to recognize meaning in the 2nd array if the input matched a value in the array so that it matches with the 1st array?
Edit: First, the program should initialize two String arrays, the first containing 10 words, and the second containing 10 meanings for those words. The order of the words and meaning should not be the same, they should be shuffled.
The program should display the two arrays in the shuffled order.
Then the program starts asking the user for the meaning of each word in the first array one by one, the user should answer with phrases from the second array.
When the user answers with a certain phrase, the orderMeanings method should be called. This method reorders the meanings as they should be aligned with the indices of words. let’s say the program asks for the meaning of “Brute” which has index 2 in array 1, the user answers “savage” which is in index 7 in the second array, the program has to swap “savage” with the word at index 2, so that savage becomes at index 2.
The program should repeat this procedure 10 times, to organize the second array with correct meanings of words from the first array.
After the 10 words are organized, the program should display word from array 1 means word from array 2 for all the items in the arrays, each on a separate line.
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
public class dic {
static String[] words = { "Inform", "Despise", "Adoration", "Famished" };
static int l = words.length;
static String[] meanings = { "explain", "hate", "love", "hungry" };
static int len = meanings.length;
static String[] words2;
public static void main(String[] args) {
randomize(l, words, len, meanings);
}
static void randomize(int l, String[] words2, int len, String[] meanings2) {
Random r = new Random();
for (int i = l - 1; i > 0; i--) {
// Pick a random index from 0 to i
int j = r.nextInt(i + 1);
// Swap array[i] with the element at random index
String temp = words2[i];
words2[i] = words2[j];
words2[j] = temp;
for (int in = len - 1; in > 0; in--) { // For meanings array
int jj = r.nextInt(in + 1);
String temp2 = meanings2[in];
meanings2[in] = meanings2[jj];
meanings2[jj] = temp2;
}
}
// Prints the random array
System.out.println(Arrays.toString(words2));
System.out.println(Arrays.toString(meanings2));
}
}