Chinaunix首页 | 论坛 | 博客
  • 博客访问: 32208
  • 博文数量: 11
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-19 21:19
文章分类
文章存档

2015年(2)

2014年(9)

我的朋友

分类: 敏捷开发

2014-11-24 21:24:16


点击(此处)折叠或打开

  1. // Arrays
  2. package main

  3. import (
  4.     "fmt"
  5. )

  6. func main() {
  7.     //Here we create an array a that will hold exactly 5 ints. The type of elements and length are both part of the array’s type. By default an array is zero-valued, which for ints means 0s.
  8.     var a [5]int
  9.     fmt.Println("emp:", a)
  10.     //We can set a value at an index using the array[index] = value syntax, and get a value with array[index].
  11.     a[4] = 100
  12.     fmt.Println("set:", a)
  13.     fmt.Println("get:", a[4])
  14.     //The builtin len returns the length of an array.
  15.     fmt.Println("len:", len(a))
  16.     //Use this syntax to declare and initialize an array in one line.
  17.     b := [5]int{1, 2, 3, 4, 5}
  18.     fmt.Println("dcl:", b)
  19.     //Array types are one-dimensional, but you can compose types to build multi-dimensional data structures.
  20.     var twoD [2][3]int
  21.     for i := 0; i < 2; i++ {
  22.         for j := 0; j < 3; j++ {
  23.             twoD[i][j] = i + j
  24.         }
  25.     }
  26.     fmt.Println("2d: ", twoD)
  27. }
转自

点击(此处)折叠或打开

  1. // Arrays
  2. package main

  3. import (
  4.     "fmt"
  5. )

  6. func main() {
  7.     //Here we create an array a that will hold exactly 5 ints. The type of elements and length are both part of the array’s type. By default an array is zero-valued, which for ints means 0s.
  8.     var a [5]int
  9.     fmt.Println("emp:", a)
  10.     //We can set a value at an index using the array[index] = value syntax, and get a value with array[index].
  11.     a[4] = 100
  12.     fmt.Println("set:", a)
  13.     fmt.Println("get:", a[4])
  14.     //The builtin len returns the length of an array.
  15.     fmt.Println("len:", len(a))
  16.     //Use this syntax to declare and initialize an array in one line.
  17.     b := [5]int{1, 2, 3, 4, 5}
  18.     fmt.Println("dcl:", b)
  19.     //Array types are one-dimensional, but you can compose types to build multi-dimensional data structures.
  20.     var twoD [2][3]int
  21.     for i := 0; i < 2; i++ {
  22.         for j := 0; j < 3; j++ {
  23.             twoD[i][j] = i + j
  24.         }
  25.     }
  26.     fmt.Println("2d: ", twoD)
  27. }


阅读(1116) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~