Golang : How to read integer value from standard input ?
Reading integer value from standard input in Golang is fairly simple with fmt.Scanf function. The code below demonstrate how to capture integer value from the standard input.
package main
import (
"fmt"
)
func main() {
var i int
fmt.Println("Enter an integer value : ")
_, err := fmt.Scanf("%d", &i)
if err != nil {
fmt.Println(err)
}
fmt.Println("You have entered : ", i)
}
See also : Golang : How to read float value from standard input ?
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+15.6k Golang : How to login and logout with JWT example
+9.8k Golang : Check if user agent is a robot or crawler example
+6.4k Golang : Calculate diameter, circumference, area, sphere surface and volume
+9.5k Golang : Validate IPv6 example
+47.9k Golang : How to convert JSON string to map and slice
+11.3k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+10.3k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+22.5k Golang : Set and Get HTTP request headers example
+9.9k Golang : Test a slice of integers for odd and even numbers
+9.1k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+13.4k Golang : Get user input until a command or receive a word to stop
+5.5k Unix/Linux : How to find out the hard disk size?