如何对数组中的所有数字求平方? Golang

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

Anyone can tell me the correct way to square it? The problem is invalid direct of square(type[4]int)

You probably want something like this:

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