英文:
Read user input in The Go Playground
问题
我在Go语言中编写了我的第一个程序,但我不明白为什么当我使用Go平台(https://go.dev/play/)时,程序不等待用户输入。
package main
import (
"fmt"
)
func main() {
var eleLen int
var givenNUM int
var TF bool
fmt.Println("Enter the length of array: ")
fmt.Scanln(&eleLen)
arr := make([]int, eleLen)
for i := 0; i < eleLen; i++ {
fmt.Scanln(&arr[i])
}
fmt.Println("Enter number: ")
fmt.Scanln(&givenNUM)
for i := 0; i < eleLen; i++ {
if arr[i] >= givenNUM {
continue
} else {
TF = false
}
}
fmt.Println(TF)
}
我得到的输出是:
Enter the length of array:
Enter number:
false
Program exited.
我没有输入数组和数字的选项。
英文:
I made my first program in the Go language and I don't understand why when I use the Go platform: (https://go.dev/play/ ) the program doesn't wait for user input.
package main
import (
"fmt"
)
func main() {
var eleLen int
var givenNUM int
var TF bool
fmt.Println("Enter the length of array: ")
fmt.Scanln(&eleLen)
arr := make([]int, eleLen)
for i := 0; i < eleLen; i++ {
fmt.Scanln(&arr[i])
}
fmt.Println("Enter number: ")
fmt.Scanln(&givenNUM)
for i := 0; i < eleLen; i++ {
if arr[i] >= givenNUM {
continue
} else {
TF = false
}
}
fmt.Println(TF)
}
The output that I get is:
Enter the length of array:
Enter number:
false
Program exited.
I don't have the option to input the array and numbers.
答案1
得分: 1
在https://go.dev/play/的Playground编辑器下方的注释中写道:
> Playground程序与外部世界的唯一通信方式是通过向标准输出和标准错误输出写入信息。
英文:
The notes under the Playground editor at https://go.dev/play/ state:
> The only communication a playground program has to the outside world is by writing to standard output and standard error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论