我写了以下代码:
package buck;
import java.util.Scanner;
class apples {
public static void main(String args[]) {
Scanner bucky = new Scanner(System.in);
double fnum, snum, answer;
System.out.println("Enter first number: ");
fnum = bucky.nextDouble();
System.out.println("Enter second number: ");
snum = bucky.nextDouble();
answer = fnum + snum;
System.out.println(answer);
}
}
当我在输入第一个号码时提到一个双号码时,它不会转到第二个指令,我得到的是:
Enter first number:
12.2
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at buck.apples.main(apples.java:10)
你能帮帮我吗?
答案 0 :(得分:0)
你必须输入不是双倍的
例如。 2.15是双数字
但是2,15不是。