当我输入整数,如5,7,14等,一切正常。但是当我输入例如7.5时,我得到一个错误。错误在哪里?
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at Exercise_11.main(Exercise_11.java:8)
下面是代码:
import java.util.Scanner;
public class Exercise_11 {
public static void main(String[] args) {
Scanner radius = new Scanner(System.in);
System.out.print("Please input the radius of circle: ");
double r= radius.nextDouble();
double l= 2*Math.PI*r;
double s= Math.PI*r*r;
System.out.println("Length = " + l);
System.out.println("Area = " + s);
}
}
1条答案
按热度按时间xqk2d5yq1#
系统的区域设置不支持将点作为小数点分隔符。使用支持点作为分隔符的区域设置,例如。
Locale.ENGLISH
.示例运行: