mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:55:28 +08:00
Update hello_who.go (#635)
练习 12.5:hello_who.go 写一个"Hello World"的变种程序:把人的名字作为程序命令行执行的一个参数, 比如:hello_who Evan Michael Laura 那么会输出Hello Evan Michael Laura! 按照原实现,与题目中的示例不符
This commit is contained in:
@@ -7,10 +7,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main(){
|
||||||
who := "World"
|
who := ""
|
||||||
if len(os.Args) > 1 { // os.Args[0] == hello_who
|
if len(os.Args) > 1 {
|
||||||
who = strings.Join(os.Args[1:], " ")
|
who += strings.Join(os.Args[1:], " ")
|
||||||
}
|
}
|
||||||
fmt.Println("Hello", who, "!")
|
fmt.Printf("Hello %s!\n",who)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user