(Go)05.基本数据类型和操作符
保留的关键字段
1.Question1
1 package main 2 3 4 import ( 5 "fmt" 6 ) 7 8 func list(n int) { 9 10 for i := 0; i <= n; i++ { 11 fmt.Printf("%d+%d=%d\n", i, n - i, n) 12 } 13 } 14 15 func main() { 16 list(10) 17 }
2.Question2
代码目录结构
1 package add 2 3 4 var Name string = "hello world" 5 var Age int = 20
1 package main 2 3 4 import ( 5 "go_dev/day2/example2/add" 6 "fmt" 7 ) 8 9 10 func main() { 11 12 fmt.Println("Name =", add.Name) 13 fmt.Println("age =", add.Age) 14 }
验证结果必须以大写字母开头
3.Question3
1 package main 2 3 import ( 4 "time" 5 "fmt" 6 ) 7 8 9 const ( 10 Female = 2 11 Man =1 12 ) 13 14 func main() { 15 for { 16 second := time.Now().Unix() 17 if (second % Female ==0) { 18 fmt.Println("Female") 19 } else { 20 fmt.Println("Man") 21 } 22 time.Sleep(1000 * time.Millisecond) 23 } 24 }
#Millisecond 毫秒
D:\project>go build -o bin/day2_example3.exe go_dev/day2/example3/main
1 D:\project>bin\day2_example3.exe 2 Man 3 Female 4 Man 5 Female 6 Man 7 Female 8 Man 9 Female 10 Man 11 Female