gpt4 book ai didi

java - 将文件数组链接到字符串数组

转载 作者:行者123 更新时间:2023-12-01 09:33:05 24 4
gpt4 key购买 nike

我正在编写一个拼字比赛,我需要帮助。这样,当用户单击按钮时,就会播放声音文件,并提供一个文本字段供用户拼写声音文件中发音的单词。之后用户用按钮确认!如果输入的文本与声音文件的文本匹配,则用户是正确的。否则,用户是错误的...我创建了一个包含 50 个内容的文件数组和一个包含 50 个内容的字符串数组...我想以这种方式链接它们...请有任何想法!我是新来的!

最佳答案

首先,构建数组,使文件数组中元素 x 处的声音与字符串数组中元素 x 处的单词相匹配。当您播放声音时,将其元素的索引保存在数组中。当用户输入一个单词时,检查它是否在您的字符串数组中,如果是,检查它的索引是否与声音文件的索引匹配,如果是,则他们拼写的单词是正确的。

//The index of the sound and input from user
int soundToPlay;
String input;

Private int findStringIndex(String input){
for(int i = 0; i < yourStringArray.length; i++){
if(yourStringArray[i].equals(input){
return i;
}
}
//not sure if java will allow you to send null like this. If not, you will have to find another way to deal with a string that isnt in your array
return null;
}

private void findMatch(int soundToPlay, String input){
int index = findStringIndex(input);
if(index == null){
//String not in array, notify user
}
if(index == soundToPlay){
//match found, notify user, play next sound
}
}

关于java - 将文件数组链接到字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39238116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com