线程" main"中的InputMismatchException

时间:2017-02-05 09:41:55

标签: java inputmismatchexception

首先,我在Java中竞争noob。我试图获得用户输入。每当我尝试输入双变量时,Eclipse都会显示此错误:

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 lesson1.MyClass.main(MyClass.java:10)

到目前为止,这是我的代码:

import java.util.Scanner;

public class MyClass {

public static void main(String[] args) {
Scanner scan1 = new Scanner(System.in);
System.out.println("Enter some decimal value");
double userInput = scan1.nextDouble();
System.out.println("The entered value is ");
System.out.print(userInput);
}

1 个答案:

答案 0 :(得分:0)

以上代码是对的! 您必须确保输入小数,例如12.3 以下是我的测试: Test Result