1
import java.util.*;
public class DriverExam
{
    private String[] answers = {"B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"};
    private String[] input_validation = {"A", "B", "C", "D"};
    private String[] student_answers = new String[20];
    private int[] missed = new int[20];
    private int[] copy_missed;
    private boolean pass=true;
    private int number_missed = 0;
    Scanner kb = new Scanner(System.in);
    String input;

    private String input()
    {
        input = kb.nextLine();
        while(!(input.equalsIgnoreCase("A")||input.equalsIgnoreCase("B")||input.equalsIgnoreCase("C")||input.equalsIgnoreCase("D")))
        {
            System.out.print("Please enter either A, B, C or D: ");
            input = kb.nextLine();
        }
        return input;
    }

    public boolean passed(String[] student_answers)
    {
        int v=0;

        for(int i=0; i<answers.length; i++)
        {
            if(!(answers[i].equalsIgnoreCase(student_answers[i])))
            {
                number_missed++;
                missed[v]=i;
                v++;

            }

        }
        if(number_missed>5)
        {
            pass=false;
        }
        return pass;
    }

    public String[] setStudentAnswers()
    {
        int question = 1;
        for(int i=0; i<student_answers.length; i++)
        {
            System.out.print("Enter the answer for question "+ question + ": ");
            student_answers[i]=input();
            question++;
        }

        return student_answers;
    }

    public int totalCorrect()
    {
        int correct = 20 - number_missed;
        return correct;
    }

    public int totalIncorrect()
    {
        return number_missed;
    }

    public int[] questionsMissed()
    {
        int[] copy_missed = Arrays.copyOfRange(missed, 0, number_missed);   
        return copy_missed;
    }

}

更具体地说,在方法questionsMissed()中,cannot find symbol当涉及到Arrays.copyOfRange.

我检查了语法,我似乎是正确missedint[]0intnumber_missed也是一个 int。

我很困惑为什么它不起作用。

4

2 回答 2

0

在 JDK 1.5+ 你应该使用

System.arraycopy()

代替

Arrays.copyOfRange()
于 2013-03-04T04:53:20.397 回答
0

jGRASP 主页指出最新版本只需要 JDK 1.5 即可运行,而Arrays.copyOfRange()直到 JDK 1.6 才添加。见证1.5 中的 Arrays 文档中缺少任何此类方法。我对 jGRASP 一无所知,但我猜你只是在后台运行旧的 JDK,因为该错误非常肯定是因为该方法不可用。

于 2013-03-04T04:43:25.860 回答