英文:
How do I print "Hello, World!" 100 times in Go?
问题
我到目前为止有这个,但是我不确定要添加什么来使它打印出“Hello, World!”100次...我该怎么做?
package main
import "fmt"
func main() {
for i := 0; i < 100; i++ {
fmt.Println("Hello, World!")
}
}
英文:
I have this so far, but I'm not sure what to add to make it print "Hello, World!" 100 times... How can I do it?
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
答案1
得分: 4
这将类似于(假设其他代码是正确的):
package main
import "fmt"
func main() {
for i := 0; i < 100; i++ {
fmt.Println("你好世界")
}
}
英文:
That would be something like (assuming the other code is correct):
package main
import "fmt"
func main() {
for i := 0; i < 100; i++ {
fmt.Println("Hello world")
}
}
答案2
得分: 4
你应该绝对使用*strings.Repeat*:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Print(strings.Repeat("Hello, World!\n", 100))
}
英文:
You should definitely use strings.Repeat:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Print(strings.Repeat("Hello, World!\n", 100))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论