go语言学习5 读取输入

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	/*
		输入与输出
		fmt包:输入输出
		输出:
			Print()//打印
			Printf()//格式化打印
			Println()//打印之后换行

		格式化打印占位符:
			%v:原样输出
			%T:打印类型
			%t:bool类型
			%s:字符串
			%f:浮点数
			%d:10进制整数
			%b:2进制整数
			%o:8进制
			%x,%X:16进制
				%x:0-9,a-f
				%X:0-9,A-F
			%c:打印字符
			%p,打印地址

		输入:
			Scanln()

		bifio包
	*/
	a := 100
	b := 3.14
	c := true
	d := "hello world"
	e := `ruby`
	f := 'A'
	fmt.Printf("%T,%b\n",a,a)
	fmt.Printf("%T,%f\n",b,b)
	fmt.Printf("%T,%t\n",c,c)
	fmt.Printf("%T,%s\n",d,d)
	fmt.Printf("%T,%s\n",e,e)
	fmt.Printf("%T,%d,%c\n",f,f,f)

	fmt.Printf("%v\n",a)
	fmt.Printf("%v\n",b)
	fmt.Printf("%v\n",c)
	fmt.Printf("%v\n",d)
	fmt.Printf("%v\n",e)
	fmt.Printf("%v\n",f)

	var x int
	var y float64
	fmt.Println("please input")
	fmt.Scanln(&x,&y)//读取键盘输入,通过操作地址,赋值给x,y 阻塞式
	fmt.Printf("a:%d,b:%f",x,y)

	fmt.Scanf("%d,%f",&x,&y)
	fmt.Printf("x:%d,y:%f",x,y)

	fmt.Println("please input")
	reader:=bufio.NewReader(os.Stdin)
	s1,_:=reader.ReadString('\n')
	fmt.Println("data:",s1)
}
int,1100100
float64,3.140000
bool,true
string,hello world
string,ruby
int32,65,A
100
3.14
true
hello world
ruby
65
please input
100 3.14
a:100,b:3.140000222,3456.2
x:222,y:3456.200000please input
122
data: 122

发布了57 篇原创文章 · 获赞 59 · 访问量 9694

猜你喜欢

转载自blog.csdn.net/AI_LINNGLONG/article/details/105315078
今日推荐