解决JAVA报错问题:
Exception in thread “main” java.util.InputMismatchException …
package youxi
;
import java
.util
.Scanner
;
public class BMI {
public static void main(String
[] args
) {
Scanner in
= new Scanner(System
.in
);
System
.out
.println("请输入身高(m):");
float a
=in
.nextInt();
System
.out
.println("请输入体重(kg):");
float b
=in
.nextInt();
float c
=b
/(a
*a
);
System
.out
.println("当前的BMI是:"+c
);
}
}
出现以下问题: 解决方法:
当使用float变量时,float a=in.nextInt();要改成float a=in.nextFloat();
当使用double变量时,double a=in.nextInt();要改成double a=in.nextDouble;
输出结果: