0
首先,我在Java中竞争noob。我试图获得用户输入。 Eclipse中显示了这个错误,每当我尝试键入双变量:线程“main”中的InputMismatchException
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);
}
好像有什么noticably错误的代码,它可能是扫描仪不能从你的输入解析双。尝试输入一个数字,然后输入文字并比较结果 – Nic
你究竟输入了什么? –
在控制台中,写如11.111之类的数字值,如果你写了String,那么它会抛出这样的错误。 – yash