Logo

Programming-Idioms

History of Idiom 120 > diff from v30 to v31

Edit summary for version 31 by programming-idioms.org:
[Go] Missing import

Version 30

2018-06-24, 08:09:47

Version 31

2018-06-24, 08:10:24

Idiom #120 Read integer from stdin

Read an integer value from the standard input into variable n.

Idiom #120 Read integer from stdin

Read an integer value from the standard input into variable n.

Imports
Imports
import "fmt"
Code
_, err := fmt.Scanf("%d", &n)
Code
_, err := fmt.Scanf("%d", &n)
Comments bubble
This parses decimal numbers (even if they have a trailing 0)
Doc URL
https://golang.org/pkg/fmt/#Scanf
Doc URL
https://golang.org/pkg/fmt/#Scanf
Demo URL
https://play.golang.org/p/mw1N0O5lgQp
Demo URL
https://play.golang.org/p/mw1N0O5lgQp