商君

导航

2018年10月12日 #

Go Example--switch

摘要: ```go package main import ( "fmt" "time" ) func main() { i := 2 fmt.Print("write ", i, " as ") //switch 语句第一种使用方式,i与case去逐个匹配 switch i { case 1: fmt.P 阅读全文

posted @ 2018-10-12 16:34 漫步者01 阅读(89) 评论(0) 推荐(0) 编辑

Go Example--if语句

摘要: ```go package main import "fmt" func main() { //if else 条件都不需要括号,{}是需要的 if 7 % 2 == 0 { fmt.Println("7 is even") } else { fmt.Println("7 is odd") } if 阅读全文

posted @ 2018-10-12 16:23 漫步者01 阅读(149) 评论(0) 推荐(0) 编辑

Go Example--for循环

摘要: ```go package main import "fmt" func main() { i := 1 //Go循环只有for, 第一种循环方式 for i 阅读全文

posted @ 2018-10-12 16:12 漫步者01 阅读(110) 评论(0) 推荐(0) 编辑

Go Example--常量

摘要: ```go package main import ( "fmt" "math" ) const s string = "constant" //定义字符串常量 func main() { fmt.Println(s) const n = 50000000 //无类型常量 const d = 3e20 /n //float64常量 fmt.Println(d) fmt.Pri... 阅读全文

posted @ 2018-10-12 15:28 漫步者01 阅读(69) 评论(0) 推荐(0) 编辑

Go Example--变量

摘要: ```go package main import "fmt" //通过import导入fmt标准包 func main() { //定义变量,并初始化 var a string = "initial" fmt.Println(a) var b, c int = 1, 2 fmt.Println(b, c) //另一种定义方式,根据初始化值推断变量的类型 var d = true... 阅读全文

posted @ 2018-10-12 15:17 漫步者01 阅读(72) 评论(0) 推荐(0) 编辑

Go Example--值运算

摘要: ```go package main import "fmt" //通过import导入fmt标准包 func main() { //+号可以用做连接字符串 fmt.Println("go" + "lang") //整数运算 fmt.Println("1+1=", 1+1) //浮点数运算 fmt.Println("7.0/3.0=", 7.0/3.0) //bool运算 fm... 阅读全文

posted @ 2018-10-12 15:06 漫步者01 阅读(98) 评论(0) 推荐(0) 编辑

Go Example--Hello

摘要: Hello world 阅读全文

posted @ 2018-10-12 14:56 漫步者01 阅读(89) 评论(0) 推荐(0) 编辑