在Go Playground中读取用户输入

huangapple go评论93阅读模式
英文:

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 (
	&quot;fmt&quot;
)

func main() {
	var eleLen int
	var givenNUM int
	var TF bool

	fmt.Println(&quot;Enter the length of array: &quot;)
	fmt.Scanln(&amp;eleLen)

	arr := make([]int, eleLen)
	for i := 0; i &lt; eleLen; i++ {

		fmt.Scanln(&amp;arr[i])
	}
	fmt.Println(&quot;Enter number: &quot;)
	fmt.Scanln(&amp;givenNUM)

	for i := 0; i &lt; eleLen; i++ {
		if arr[i] &gt;= 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.

huangapple
  • 本文由 发表于 2022年3月16日 20:33:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/71497160.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定