小编Trầ*_*ung的帖子

为什么我得到InputMismatchException?

到目前为止我有这个:

public double checkValueWithin(int min, int max) {
    double num;
    Scanner reader = new Scanner(System.in);
    num = reader.nextDouble();                         
    while (num < min || num > max) {                 
        System.out.print("Invalid. Re-enter number: "); 
        num = reader.nextDouble();                         
    }
    return num;
}
Run Code Online (Sandbox Code Playgroud)

还有这个:

public void askForMarks() {
    double marks[] = new double[student];
    int index = 0;
    Scanner reader = new Scanner(System.in);
    while (index < student) {
        System.out.print("Please enter a mark (0..30): ");
        marks[index] = (double) checkValueWithin(0, 30); 
        index++;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我测试这个,它不能采取双数,我得到这个消息:

Exception in thread …
Run Code Online (Sandbox Code Playgroud)

java input java.util.scanner inputmismatchexception

5
推荐指数
2
解决办法
13万
查看次数