我试图提示用户输入 x 坐标,但是当我写一个十进制数(例如 2.1)作为输入时,这会导致问题。我该如何解决这个问题?
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.