(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 }
main.go

2.Question2

代码目录结构

1 package add
2 
3 
4 var Name string = "hello world"
5 var Age int = 20
add.go
 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 }
main.go

验证结果必须以大写字母开头

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 }
main.go

#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

 

posted @ 2019-01-24 15:51  lvelvis  阅读(202)  评论(0编辑  收藏  举报
#####