switch分支1
This commit is contained in:
39
main.go
39
main.go
@@ -3,19 +3,30 @@ package main
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// 指定变量类型并且赋值
|
||||
var num1 int = 18
|
||||
fmt.Println(num1)
|
||||
score := 87
|
||||
switch score / 10 {
|
||||
case 10:
|
||||
fmt.Println("You are 10%")
|
||||
case 9:
|
||||
fmt.Println("You are 9%")
|
||||
case 8:
|
||||
fmt.Println("You are 8%")
|
||||
case 7:
|
||||
fmt.Println("You are 7%")
|
||||
case 6:
|
||||
fmt.Println("You are 6%")
|
||||
case 5:
|
||||
fmt.Println("You are 5%")
|
||||
case 4:
|
||||
fmt.Println("You are 4%")
|
||||
case 3:
|
||||
fmt.Println("You are 3%")
|
||||
case 2:
|
||||
fmt.Println("You are 2%")
|
||||
case 1:
|
||||
fmt.Println("You are 1%")
|
||||
|
||||
// 指定变量类型,但不赋值,使用默认值
|
||||
var num2 int
|
||||
fmt.Println(num2)
|
||||
|
||||
// 自动类型推断
|
||||
var num3 = "tom"
|
||||
fmt.Println(num3)
|
||||
|
||||
// 省略var =写为:=
|
||||
num4 := "男"
|
||||
fmt.Println(num4)
|
||||
default:
|
||||
fmt.Println("You are 0%")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user