inputmismatchexception

Why am I getting InputMismatchException?

♀尐吖头ヾ 提交于 2019-11-26 03:24:40
问题 So far I have this: 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; } and this: 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

Why am I getting InputMismatchException?

☆樱花仙子☆ 提交于 2019-11-26 02:20:58
So far I have this: 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; } and this: 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++; } } When I test this, it can't take double number and I