I need to create a code in Java which takes user input (a word) and search through first Array of String, if found the word in that array, print out the meaning of that word from second array.
for example:
First String Array: {"Computer", "Java", "Stack Overflow"} Second String Array: {"Machine","Programming","Amazing people"}
So, if user input is: Computer The print out should be Machine
if user input is: Java The print out should be Programming.
See my code below. No matter what user type, it just give first index from second Array.
I will really appreciate your help.
Thank you in Advance!
Regards,
Vikram
import java.util.Arrays;
import javax.swing.JOptionPane;
public class Test {
public static void main(String[] args) {
String [] MyString = {"Computer","Science","Java", "Coding"};
String [] Meaning = {"Machine","Life","Programming","Programer"};
String MySearch;
int i =0; int j =0;
MySearch = JOptionPane.showInputDialog(null, "Enter Your Word to Search");
while ( i < MyString.length){
if(String.valueOf(MySearch).equals (Arrays.asList(MyString[i]))){
while(j < Meaning.length){
j++;
}
}
i++;
}
System.out.println(Meaning[j]);
}
}