所以这就是代码,它的目的是从列表中给出一个随机单词,让用户输入外部文本文件中的含义,如果正确,它会从列表中删除该单词,否则它会保留该单词并添加将其添加到missedWord 列表中。问题是单词没有从列表中删除,而且我似乎无法打印 ArrayList。谁能帮我解决这个问题?另外,我可以对代码进行任何改进吗?感谢您的所有帮助。
import java.io.*;
import java.util.*;
public class WordList1 {
public static void main(String[] args) throws IOException{
boolean fart = true;
FileReader fr = new FileReader("WL1.txt");
BufferedReader br = new BufferedReader(fr);
Scanner console = new Scanner(System.in);
ArrayList wordArray = new ArrayList();
ArrayList missedWords = new ArrayList();
String input, stringArray[] = new String[2], answer;
while((input=br.readLine())!=null){
stringArray = input.split(" ");
wordArray.add(stringArray);
}
while(fart){
stringArray = (String[]) wordArray.get((int)(Math.random()*(wordArray.size())));
System.out.println(stringArray[0]);
answer = console.nextLine();
if(answer.equalsIgnoreCase(stringArray[1])){
System.out.println("CORRECT");
wordArray.remove(stringArray[1]);
}
if(!answer.equalsIgnoreCase(stringArray[1])){
System.out.println("INCORRECT, " + stringArray[1]);
missedWords.add(stringArray[0]);
}
if(answer.equalsIgnoreCase("escape")){
fart = false;
System.out.println(missedWords);
}
if(answer.equalsIgnoreCase("print"))
System.out.println(wordArray);
}
}
}