package main
import"fmt"funcmain(){var aSingle int
aSingle =10
fmt.Println("aSinger:",aSingle)
fmt.Println("=================first way to define array============")var aArrays [3]int
aArrays[0]=0
aArrays[1]=1
aArrays[2]=2//two ways to arrayfor i:=0; i<len(aArrays); i++{
fmt.Printf("aArrays[%d]:%d\n",i,aArrays[i])}
fmt.Println("=================================")for k,v :=range(aArrays){
fmt.Printf("aArrays[%d]:%d\n",k,v)}
fmt.Println("===============secord way to define array===============")var balance =[5]string{"zhu","shi","yong","love","go"}for i:=1;i<len(balance);i++{
fmt.Printf("balance[%d]:%s\n",i,balance[i])}
fmt.Println("=================================")for k,str:=range(balance){
fmt.Printf("balance[%d]:%s\n",k,str)}
fmt.Println("===============third way to define array===============")
balance1:=[5]string{"go","is","a","easy","lang"}for k,str:=range(balance1){
fmt.Printf("balance1[%d]:%s\n",k,str)}
fmt.Println("===============4 way to define array===============")var balance2 =[...]int{1,2,3,4,5}for i:=1;i<len(balance2);i++{
fmt.Printf("balance2[%d]:%d\n",i,balance2[i])}
fmt.Println("===============5 way to define array===============")
balance3:=[...]int{6,7,8,9,10}for k,v:=range(balance3){
fmt.Printf("balance3[%d]:%d\n",k,v)}
fmt.Println("===============6 way to define array===============")
balance4:=[5]string{1:"zhusy",3:"love",4:"go"}for i:=0;i<len(balance4);i++{
fmt.Printf("balance4[%d]:%s\n", i, balance4[i])}
fmt.Println("===============7 way to define array===============")
balance5:=[...]string{4:"you"}for k,str:=range(balance5){
fmt.Printf("balance5[%d]:%s\n", k, str)}
fmt.Println("len balance5:",len(balance5))}
一、数组的定义和访问package mainimport "fmt"func main() { var aSingle int aSingle = 10 fmt.Println("aSinger:",aSingle) fmt.Println("=================first way to define array============") var aArrays [3] int aArrays[0] = 0 aArrays[1] = 1 aArr