我想提示用戶輸入x座標,但是當我寫入一個十進制數字(如2.1)作爲輸入時,這是一個問題。如何解決該問題?掃描儀雙值 - InputMismatchException
import java.util.Scanner;
public class TwoRetangles{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.print("Enter the center x coordinate of retangle = ");
double x1=input.nextDouble();
}
}
--------------------配置:--------------------
Enter the center x coordinate of retangle = 2.1
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextDouble(Scanner.java:2456)
at TwoRetangles.main(TwoRetangles.java:6)
Process completed.
你想要一個小數或雙? – Ramin
我想要一個雙。 – user2919243