func main() {var elems,mean intsum := 0fmt.Print("Number of elements? ")fmt.Scan(&elems)var array = new([elems]int)for i := 0; i 当我试图编译它时,我收到了以下错误信息:* f8 b1 S- b9 b9 r+ J
无效数组绑定元素 9 [0 O! u, ~/ n7 w, s$ T这里有什么问题?" m% A0 R3 _2 U6 v9 ^$ g1 l
' i- e e# X7 d" z0 b# i
解决方案: 7 d% x: ^, } J. M O: Y, X
切片而非数组:[code]//var array = new([elems]int) - no,arrays are not dynamicvar slice = make([]int,elems) // or slice := make([]int,elems) % ~" O, l9 Y/ _) h9 Z
此外,您可能需要考虑回收范围:% h7 x+ v7 H; G2 c
// for i := 0; i < elems; i { - correct but less idiomaticfor i,v := range slice { - Q9 N! M# j1 Y