From e30be57a38170ea30807612e09523e79f8205941 Mon Sep 17 00:00:00 2001 From: obasang <805577846@qq.com> Date: Thu, 11 Jul 2019 12:29:40 +0800 Subject: [PATCH] Update hello_who.go (#635) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 练习 12.5:hello_who.go 写一个"Hello World"的变种程序:把人的名字作为程序命令行执行的一个参数, 比如:hello_who Evan Michael Laura 那么会输出Hello Evan Michael Laura! 按照原实现,与题目中的示例不符 --- eBook/exercises/chapter_12/hello_who.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/eBook/exercises/chapter_12/hello_who.go b/eBook/exercises/chapter_12/hello_who.go index 2175689..dacef33 100755 --- a/eBook/exercises/chapter_12/hello_who.go +++ b/eBook/exercises/chapter_12/hello_who.go @@ -1,16 +1,16 @@ // hello_who.go package main - + import ( "fmt" - "os" + "os" "strings" ) -func main() { - who := "World" - if len(os.Args) > 1 { // os.Args[0] == hello_who - who = strings.Join(os.Args[1:], " ") +func main(){ + who := "" + if len(os.Args) > 1 { + who += strings.Join(os.Args[1:], " ") } - fmt.Println("Hello", who, "!") + fmt.Printf("Hello %s!\n",who) }