Finish: 02-constants - 常量与iota
This commit is contained in:
@@ -9,9 +9,9 @@ func exercise1() {
|
||||
// GREETING: string,值为"你好,世界!"
|
||||
// MAX_COUNT: int,值为1000
|
||||
// SUCCESS: bool,值为true
|
||||
const GREETING string = ____
|
||||
const MAX_COUNT int = ____
|
||||
const SUCCESS bool = ____
|
||||
const GREETING string = "你好,世界!"
|
||||
const MAX_COUNT int = 1000
|
||||
const SUCCESS bool = true
|
||||
|
||||
fmt.Printf("问候语: %s\n最大数量: %d\n成功状态: %t\n", GREETING, MAX_COUNT, SUCCESS)
|
||||
}
|
||||
@@ -24,9 +24,9 @@ func exercise2() {
|
||||
// HTTP_NOT_FOUND: int,值为404
|
||||
// HTTP_SERVER_ERROR: int,值为500
|
||||
const (
|
||||
HTTP_OK = ____
|
||||
HTTP_NOT_FOUND = ____
|
||||
HTTP_SERVER_ERROR = ____
|
||||
HTTP_OK = 200
|
||||
HTTP_NOT_FOUND = 404
|
||||
HTTP_SERVER_ERROR = 500
|
||||
)
|
||||
|
||||
fmt.Printf("HTTP状态码: OK=%d, NOT_FOUND=%d, SERVER_ERROR=%d\n",
|
||||
@@ -63,7 +63,7 @@ func exercise4() {
|
||||
// LEVEL_4: 103
|
||||
// 提示:第一个常量使用 ioda + 100
|
||||
const (
|
||||
LEVEL_1 = iota + ____
|
||||
LEVEL_1 = iota + 100
|
||||
LEVEL_2
|
||||
LEVEL_3
|
||||
LEVEL_4
|
||||
@@ -82,9 +82,9 @@ func exercise5() {
|
||||
// GB: 1073741824 (1 << 30)
|
||||
const (
|
||||
_ = iota
|
||||
KB = 1 << ____
|
||||
MB = 1 << ____
|
||||
GB = 1 << ____
|
||||
KB = 1 << (iota * 10)
|
||||
MB
|
||||
GB
|
||||
)
|
||||
|
||||
fmt.Printf("存储单位: KB=%d, MB=%d, GB=%d\n", KB, MB, GB)
|
||||
|
||||
Reference in New Issue
Block a user