一、Java类型
1、逻辑类型
- 常量:true,false
boolean juge = true,关闭 = false;
2、整型类型
- (1)int型
int x = 12;
- (2)byte型
byte x = -12,漂亮 = 98;
byte范围:-2^7^~2^7^-1
- (3)short型
short x = 12;
- (4)long型
long x = 12L;
3、字符型
char ch = 'a';
4、浮点型
-
(1)float型
float x = 123.456f;
-
(2)double型
double x = 23.456;
二、Java的输入
Scanner reader = new Scanner(System.in);
1、Boolean(reader.nextBoolean())
boolean bool = reader.nextBoolean();
System.out.println("Boolean:"+bool);
2、Byte(reader.nextByte())
byte bte = reader.nextByte();
System.out.println("byte:"+bte);
3、Short(reader.nextShort()
short srot = reader.nextShort();
System.out.println("short:"+srot);
4、Int(reader.nextInt()
int in = reader.nextInt();
System.out.println("int:"+in);
5、long(reader.nextLong())
long lon = reader.nextLong();
System.out.println("long:"+lon);
6、Float(reader.nextFloat())
float foat = reader.nextFloat();
System.out.println("float:"+foat);
7、Double(reader.nextDouble())
double dou = reader.nextDouble();
System.out.println("double:"+dou);
8、String
(1)reader.nextLine()
String str1 = reader.nextLine();
System.out.println("nextLine:"+str1);
nextLine()会提取字符前后的空格,回车截止
(2)reader.next()
String str2 = reader.next();
System.out.println("next:"+str2);
next()只吸取字符,不会提取字符前后的空格,遇到空格、Tab键、回车时停止
9、Char(reader.next().charAt(0))
char cha = reader.next().charAt(0);
System.out.println("char:"+cha);