Explorar o código

Update hello_who.go (#635)

练习 12.5:hello_who.go 写一个"Hello World"的变种程序:把人的名字作为程序命令行执行的一个参数,
比如:hello_who Evan Michael Laura 那么会输出Hello Evan Michael Laura!
按照原实现,与题目中的示例不符
obasang %!s(int64=6) %!d(string=hai) anos
pai
achega
e30be57a38
Modificáronse 1 ficheiros con 7 adicións e 7 borrados
  1. 7 7
      eBook/exercises/chapter_12/hello_who.go

+ 7 - 7
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)
 }