你好 Stackoverflow 社区。我目前正在完成我在网上找到的旧 CS 课程学习作业。我需要使用数组将英语单词转换为法语,反之亦然,使用 2 个字符串数组和线性搜索。我设置了线性搜索,但在设置从第二个数组绘制输出的过程时遇到了困难。以下是我到目前为止汇总的内容,但正如我所说,我很难从输入中提取输出。任何指导表示赞赏!
import java.text.*; // general package for formatting
import javax.swing.*; // for GUI
public class Translation
{
public static void main(String[] args)
{
String[] eng = {"hello", "goodbye", "cat", "dog"};
String[] fre = {"bonjour", "au revoir", "le chat", "le chien"};
String word;
word = JOptionPane.showInputDialog("Enter word");
sequentialSearch(eng, word);
}
public static int sequentialSearch(new words[], int target)
{
int index;
int element;
boolean found;
index = 0;
element = -1;
found = false;
while (!found && index < words.length)
{
if (words[index] == target)
{
found = true;
element = index;
}
index++
}
return element;
}
}