package main
import (
"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)的direct无效
最佳答案
你可能想要这样的东西:
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)
}
关于go - 如何对数组中的所有数字进行平方?戈朗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27107674/