Blogger Information
Blog 70
fans 4
comment 5
visits 103781
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Go:fmt.Scanln在控制台获取用户输入的值
JiaJieChen
Original
1315 people have browsed it

一.fmt.Scanln在控制台获取用户输入的值

代码块

       
  1. packagemain
  2. import"fmt"
  3. func main(){
  4. // 在控制台录入数据 Scanln
  5. varnamestring// 姓名
  6. fmt.Println("请输入姓名")
  7. fmt.Scanln(&name)
  8. varageint// 年龄
  9. fmt.Println("请输入年龄")
  10. fmt.Scanln(&age)
  11. varheight float32// 身高
  12. fmt.Println("请输入身高")
  13. fmt.Scanln(&height)
  14. // 输入完后打印数据
  15. fmt.Printf("姓名:%v, 年龄:%v, 身高:%v",name,age,height)
  16. }

需要注意的是: 输入的值要对应类型,否则无法类型无法识别,&符号是取内存地址而来改变量值

效果图

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply withNews Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!