zl程序教程

您现在的位置是:首页 >  其他

当前栏目

2023-01-09:以下go语言代码输出什么?A:+Inf; B:zero; C:something else; D:does

2023-02-26 09:49:40 时间

2023-01-09:以下go语言代码输出什么?A:+Inf;B:zero;C:something else;D:doesn't compile。

package main

import (
    "fmt"
    "math"
)

func main() {
    // Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.
    x := math.Inf(1)
    switch {
    case x < 0, x > 0:
        fmt.Println(x)
    case x == 0:
        fmt.Println("zero")
    default:
        fmt.Println("something else")
    }
}

答案选A。这道题考的不是语法,而是英语。根据注释 Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.,即可得出答案。