public static void main(String[] args) {
//测试整型变量
int a = 15;
int b = 015; //以0开头是八进制
int c = 0x15; //以0x开头是16进制
int d = 0b1101; //以0b开头是二进制
System.out.println(b);
System.out.println(c);
System.out.println(d);
byte age = 30;
short salary = 30000;
int population = 2000000000; //整型常量默认是int类型
long globalPopulation = 7400000000L; //后面加L就是这是一个long类型的常量
}
public static void main(String[] args) {
float a = 3.14F;
double b = 6.28;
double c = 628E-2;
System.out.println(c);
// 浮点数是不精确的,一定不要用于比较!
float f = 0.1f;
double d = 1.0 / 10;
System.out.println(f == d); // 结果为false
float d1 = 423432423f;
float d2 = d1 + 1;
if (d1 == d2) {
System.out.println("d1==d2");// 输出结果为d1==d2
} else {
System.out.println("d1!=d2");
}
System.out.println("##################");
//使用精确浮点运行,推荐:BigDecimal
BigDecimal bd = BigDecimal.valueOf(1.0);
bd = bd.subtract(BigDecimal.valueOf(0.1));
bd = bd.subtract(BigDecimal.valueOf(0.1));
bd = bd.subtract(BigDecimal.valueOf(0.1));
bd = bd.subtract(BigDecimal.valueOf(0.1));
bd = bd.subtract(BigDecimal.valueOf(0.1));
System.out.println(bd);// 0.5
System.out.println(1.0 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1);// 0.5000000000000001
BigDecimal bd2 = BigDecimal.valueOf(0.1);
BigDecimal bd3 = BigDecimal.valueOf(1.0/10.0);
System.out.println(bd2.equals(bd3));
}
public static void main(String[] args) {
char a = 'T';
char b = '尚';
char c = '\u0061';
System.out.println(c);
//转义字符
System.out.println(""+'a'+'\n'+'b');
System.out.println(""+'a'+'\t'+'b');
System.out.println(""+'a'+'\''+'b'); //a'b
//String就是字符序列
String d = "abc";
//测试布尔类型
boolean man = false;
if(man){ //极端不推荐:man==true
System.out.println("男性");
}
}