码迷,mamicode.com
首页 > 其他好文 > 详细

Go的基本示例

时间:2016-09-20 12:17:32      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

有空可以看看,

不知能不能超越JAVA的作法。

hello.go

package main

import "fmt"

func main() {
    s := "hello"
    m := " world"
    a := s + m
    b := [...]int{4, 5, 6, 7,8}
    var ar = [10]byte {‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘, ‘h‘, ‘i‘, ‘j‘}
    var c, d []byte
    c = ar[2:5]
    d = ar[3:5]
    numbers := make(map[string] int)
    numbers["one"] = 1
    numbers["two"] = 10
    numbers["three"] = 3
    x := 12
    if x > 10 {
        fmt.Println("x is greater than 10")
    } else {
        fmt.Println("x is less than 10")
    }
    sum := 0;
    for index:=0; index<10;index++ {
        sum += index
    }
    fmt.Println("sum is equeal to ", sum)
    fmt.Printf("%d\n", numbers["three"])
    fmt.Printf("%d\n", c)
    fmt.Printf("%d\n", d)
    fmt.Printf("%s\n", a)
    fmt.Printf("The first element is %d\n", b[0])
}

  技术分享

Go的基本示例

标签:

原文地址:http://www.cnblogs.com/aguncn/p/5888173.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!