我正在尝试访问和存储数组中的信息' qmissed'从方法' questionsMissed',我该怎么做?
感谢您的帮助!
public class DriverExam {
public void makeMissedArray(){
int smissedarray = totalIncorrect();
int[] qmissed = new int[smissedarray];
}
public int[] questionsMissed(){
if(totalIncorrect() > 0){
makeMissedArray();
}
int x = 0;
if(totalIncorrect() == 0){
return qmissed;
}
for(int i = 0; i < 20; i++){
if(correct[i] != student[i]){
qmissed[x] = (i+1);
x++;
}
}
return qmissed;
}
}
答案 0 :(得分:1)
您希望qmissed
成为实例变量:
public class DriverExam {
int[] qmissed;
public void makeMissedArray(){
int smissedarray = totalIncorrect();
qmissed = new int[smissedarray];
}
...
}
对于DriverExam类的每个实例,都会有qmissed
的一个副本,并且可以通过该类的任何实例方法访问它。