Open In App

How to Take Input from the User in Golang?

Scanln function can be used to take the input from the user in the Golang. Below is the example of taking input from the user:




// Golang program to show how
// to take input from the user
package main
  
import "fmt"
  
// main function
func main() {
  
    // Println function is used to
    // display output in the next line
    fmt.Println("Enter Your First Name: ")
  
    // var then variable name then variable type
    var first string
  
    // Taking input from user
    fmt.Scanln(&first)
    fmt.Println("Enter Second Last Name: ")
    var second string
    fmt.Scanln(&second)
  
    // Print function is used to
    // display output in the same line
    fmt.Print("Your Full Name is: ")
  
    // Addition of two string
    fmt.Print(first + " " + second)
}

Now save this file and execute as shown in the below screenshot:



Description About the Program:



Article Tags :