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