因此我的程序应该打印出我使用多线程的数组,我不知道为什么不输出到控制台,但我知道它是在我的getter和setter中,但我环顾四周,并没有找到解决方案。这是我的代码。
public class multithreadTest{
private static class Test implements Runnable{
private String [] questions;
private String [] answers;
private String [] category;
public Test(String[] questions, String[] answers, String[] category){
this.questions = questions;
this.answers = answers;
this.category = category;
}
public String[] getQuestions(){ return this.questions;}
public String[] getAnswers(){return this.answers;}
public String[] getCategory(){return this.category;}
public void run(){
System.out.println("Q: " + questions[1] + "A: " + answers[1] + "C: " + category[1]);
}
}
public static void main(String[]args){
String [] questions = new String[100];
String [] answers = new String[100];
String [] category = new String[100];
try{
File file = new File("Questionbank.txt");
Scanner sc = new Scanner(file);
int l = 0;
while(sc.hasNextLine()) {
String line = sc.nextLine();
String [] words = line.split("::");
questions[l] = words[0];
answers[l] = words[1];
category[l] = words[2];
//System.out.println("Q: " + Questions[l] + "A: " + Answers[l] + "C: " + Category[l]);
l++;
}
}catch(FileNotFoundException e){
e.printStackTrace();
}
Thread t = new Thread(new Test(questions,answers,category));
t.start();
}
}