package com.Head.Day002;
public class VarDemo {
public static void main(String[] args) {
//1. int:整型,4个字节,范围:-21亿多—21亿多
int a = 250;//直接量
// int b = 10000000000; 编译错误 超出int范围
int a3 = 2147483647; //int型最大值
a += 1; //a编程最大负值,发生溢出(溢出发生在运行阶段)
System.out.println(5/2);//输出2
System.out.println(2/5);//输出0
//2. long:长整型,8个字节。
long a1 = 250L;
long b1 = 10000000000L;
long c = 1000000000*2*10L;
System.out.println(c);//输出200亿
long d = 1000000000*3*10L;//超出范围 运行溢出
//所以建议带L的整型变量放在运算最前面
long e = System.currentTimeMillis();
double y0 = 25.678;//默认为double
float y1 = 25.678F;//float直接量应加F
double y2 = 5/2;
System.out.println(y2);//输出2.0
double y3 = 5.0/2;
System.out.println(y3);//输出2.5
double y4 = 3.0;
double y5 = 2.9;
System.out.println(y4-y5);//按理为0.1,实际结果0.10000000000000009,浮点数
//4.boolean类型:布尔型,1个字节,只能存放true或false
boolean z0 = true;
boolean z1 = false;
// boolean z2 = 25; 错位,不能存放数
//5.char:字符型,2个字节
char h0 = '0';
char h1 = 'a';
char h2 = '灿';
char h3 = 'A';
// char h4 = ''; 单引号里面必须有值
// char h5 = 天; 字符型直接量必须放在单引号中
}
}
public class VarDemo {
public static void main(String[] args) {
//1. int:整型,4个字节,范围:-21亿多—21亿多
int a = 250;//直接量
// int b = 10000000000; 编译错误 超出int范围
int a3 = 2147483647; //int型最大值
a += 1; //a编程最大负值,发生溢出(溢出发生在运行阶段)
System.out.println(5/2);//输出2
System.out.println(2/5);//输出0
//2. long:长整型,8个字节。
long a1 = 250L;
long b1 = 10000000000L;
long c = 1000000000*2*10L;
System.out.println(c);//输出200亿
long d = 1000000000*3*10L;//超出范围 运行溢出
//所以建议带L的整型变量放在运算最前面
long e = System.currentTimeMillis();
System.out.println(e);
//3. double:浮点数,8个字节
double y0 = 25.678;//默认为double
float y1 = 25.678F;//float直接量应加F
double y2 = 5/2;
System.out.println(y2);//输出2.0
double y3 = 5.0/2;
System.out.println(y3);//输出2.5
double y4 = 3.0;
double y5 = 2.9;
System.out.println(y4-y5);//按理为0.1,实际结果0.10000000000000009,浮点数
//4.boolean类型:布尔型,1个字节,只能存放true或false
boolean z0 = true;
boolean z1 = false;
// boolean z2 = 25; 错位,不能存放数
//5.char:字符型,2个字节
char h0 = '0';
char h1 = 'a';
char h2 = '灿';
char h3 = 'A';
// char h4 = ''; 单引号里面必须有值
// char h5 = 天; 字符型直接量必须放在单引号中
}
}