How Golang receives input

angryTom
Release: 2020-03-18 13:31:29
Original
3261 people have browsed it

How Golang receives input

How Golang receives input

A practical program should include a series of operations such as input, processing, and output. You can use Golang to receive input. The Scanln method in the fmt package is implemented.

The specific usage is as follows:

package main

import "fmt"

//var   a,b int = 10,20

func main()  {
   //fmt.Println(a,b)
   // b,a = a,b
   // fmt.Println(a,b)
   //要求: 可以从控制台接受用户的信息 【姓名,年龄,薪水,是否通过考试】
   //方式1 fmt.Scanln()
   var  name string
   var  age  byte
   var  sal  float32
   var ispass bool
   fmt.Println("请输入姓名:")
   //当程序执行到fmt.Scanln(&name),程序会停止执行等待用户输入
   fmt.Scanln(&name)
   fmt.Println("请输入年龄:")
   //当程序执行到fmt.Scanln(&age),程序会停止执行等待用户输入
   fmt.Scanln(&age)
   fmt.Println("请输入薪水:")
   //当程序执行到fmt.Scanln(&sal),程序会停止执行等待用户输入
   fmt.Scanln(&sal)
   fmt.Println("请输入是否通过:")
   //当程序执行到fmt.Scanln(&name),程序会停止执行等待用户输入
   fmt.Scanln(&ispass)
   fmt.Printf(" The name is:%s,age:%d,sal:%f, ispass :%t",name,age,sal,ispass)

}
Copy after login

For more golang knowledge, please pay attention to the golang tutorial column of the PHP Chinese website.

The above is the detailed content of How Golang receives input. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!