package mainimport ( "fmt")func main() { var square int box := [4]int{1, -2, 3, 4} square = box * *box fmt.Println("The square of the first box is", square)}谁能告诉我正确的平方方法?问题是无效直接的 square(type[4]int)
1 回答
小唯快跑啊
TA贡献1863条经验 获得超2个赞
你可能想要这样的东西:
package main
import (
"fmt"
)
func main() {
box := []int{1, -2, 3, 4}
square := make([]int, len(box))
for i, v := range box {
square[i] = v*v
}
fmt.Println("The square of the first box is ", square)
}
- 1 回答
- 0 关注
- 188 浏览
添加回答
举报
0/150
提交
取消