gpt4 book ai didi

java - 错误 java.util.InputMismatchException

转载 作者:行者123 更新时间:2023-12-01 23:30:59 27 4
gpt4 key购买 nike

我是Java新手,正在尝试编写一个程序来查看一个人的体温是否正常,不是太低或太高。

我收到此错误消息:(当我输入 double ,而不是整数时)

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)

这是我的代码

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");
}
}
}

最佳答案

您似乎输入了一个非双值作为程序的输入,因此在执行时遇到InputMismatchException:

tast.nextDouble();

关于java - 错误 java.util.InputMismatchException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19301964/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com