[英]error java.util.InputMismatchException
I am new to Java, and am trying to make a program to see if a person has a normal temperature, not too low or too high. 我是Java的新手,正在尝试制作一个程序来查看一个人的温度是否正常,而不是太低或太高。
I have been getting this error message:(when I'am input a double, not a int) 我一直收到此错误消息:(当我输入双精度值而不是整数时)
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 ekstra217.main(ekstra217.java:15)
Here is my code 这是我的代码
import java.util.*;
class temp
{//klassen start
public static void main(String[]args)
{//main start
Scanner tast=new Scanner(System.in);
System.out.println("Write your temperatur!");
//normal temperatur is between 36.5 and 37.5
double temperatur=tast.nextDouble();
if (temperatur<36.5)
{
System.out.println("Your temperatur is normal");
}
else if(temperature>37.5)
{//else if starts
System.out.println("You have over normal,you are sick");
}//else if slutter
else{
System.out.println("You have normal temperature");
}
}
}
您似乎正在输入non-double
InputMismatchException
值作为程序的输入,因此在执行时遇到InputMismatchException
:
tast.nextDouble();
You may want to wrap your data reading into an if
like this: 您可能希望将数据读取包装为
if
例如:
if (tast.hasNextDouble())
tast.next.Double;
else {
// print something and exit
System.out.println("Incorrect temperature value!!!);
System.exit(1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.