my first go


/**
* Created with IntelliJ IDEA.
* User: li_zhe
* Date: 14/05/06
* Time: 12:34
* To change this template use File | Settings | File Templates.
*/
package main

//实现格式化的I/O
import "fmt"

func main() {

//var a int
//var b bool

//a = 15
//b = false

a := 15
b :=false

fmt.Println(a)
fmt.Println(b)

//var (
//a int
//b bool
//)

c,d := 12,15
fmt.Println(c)
fmt.Println(d)

//任何赋给‘_‘的值都会被丢弃
_,e := 20,21
fmt.Println(e)

fmt.Printf("Hello world!")

const (
l = iota
j = iota
)
fmt.Println(l)
fmt.Println(j)

var s string = "HELLO"
by := []byte(s)
by[0] = ‘c‘

s2 := string(by)
fmt.Printf("%s\n" , s2)

}


/**
* Created with IntelliJ IDEA.
* User: li_zhe
* Date: 14/05/13
* Time: 11:25
* To change this template use File | Settings | File Templates.
*/
package main

import "fmt"

func main() {

s := "HELLO " + "WORLD"
fmt.Printf(s+"\n")

var c complex64 = 5+5i
fmt.Printf("Value is: %v",c)
fmt.Printf("\n")

list := []string{"a","b","c","d","e"}

for k,v := range list {

fmt.Println(k)
fmt.Printf(v+"\n");
}

for pos,char := range "Process" {
fmt.Printf("Charactor ‘%c‘ starts at byte position %d\n",char,pos)
}

for i := 0 ;i < 10 ;i++ {

if i > 5 {
continue
}
fmt.Println(i)
}

fmt.Println("===============================")

K: for i := 0;i < 10; i++ {
for j := 0;j < 10; j++ {

if j > 5 {
break K
}
fmt.Println(j)
}
}

i := 0
switch i {

case 0:fallthrough
case 1:
fmt.Printf("is 1!")
default:
fmt.Printf("is default!")
}

switch i {

case 0,1,2,3:
fmt.Printf("true!")
case 5:
fmt.Printf("is 1!")
default:
fmt.Printf("is default!")
}
}

my first go,布布扣,bubuko.com

时间: 2024-11-03 03:43:14