题解 | #体温异常#
体温异常
http://www.nowcoder.com/practice/9baeccf93a58410f9325d70300ce000f
真正的使用panic 和 recover defer去实现 直接if判断 没啥意思 这里注意的是 一定要给出返回值 也就是说 函数的返回值提前声明,这使得defer可以直接访问该返回值(因为传入了返回值的地址指针)
//import "fmt"
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param t double浮点型 体温
* @return string字符串
*/
func temperature(t float64) (ans string) {
// write code here
ans = ""
defer func() {
err := recover()
if err != nil {
ans = "体温异常"
}
}()
if t > 37.5 {
panic("体温异常 弹出警告!")
}
return ans
}