a==b,b==c都为true,那a==c一定为true吗???
Java经验总结
共 2186字,需浏览 5分钟
·
2022-02-28 08:55
int a = 50;
Integer a1 = 50;
Integer b1 = 50;
Integer c1 = 100;
Integer d1 = a1 + b1;
System.out.println(a == a1);
System.out.println(a == b1);
System.out.println(a1 == b1);
System.out.println(c1 == (a1 + b1));
System.out.println(c1 == d1);
int a = 100;
Integer a1 = 100;
Integer b1 = 100;
Integer c1 = 200;
Integer d1 = a1 + b1;
System.out.println(a == a1);
System.out.println(a == b1);
System.out.println(a1 == b1);
System.out.println(c1 == (a1 + b1));
System.out.println(c1 == d1);
int a = 200;
Integer a1 = 200;
Integer b1 = 200;
Integer c1 = 400;
Integer d1 = a1 + b1;
System.out.println(a == a1);
System.out.println(a == b1);
System.out.println(a1 == b1);
System.out.println(c1 == (a1 + b1));
System.out.println(c1 == d1);
double a = 50d;
Double a1 = 50d;
Double b1 = 50d;
Double c1 = 100d;
Double d1 = a1 + b1;
System.out.println(a == a1);
System.out.println(a == b1);
System.out.println(a1 == b1);
System.out.println(c1 == (a1 + b1));
System.out.println(c1 == d1);
double a = 200d;
Double a1 = 200d;
Double b1 = 200d;
Double c1 = 400d;
Double d1 = a1 + b1;
System.out.println(a == a1);
System.out.println(a == b1);
System.out.println(a1 == b1);
System.out.println(c1 == (a1 + b1));
System.out.println(c1 == d1);
double a = 0.1d;
double b = 0.2d;
double c = 0.3d;
System.out.println(c == (a + b));
System.out.println(0.3d == (a + b));
float a = 0.1f;
float b = 0.2f;
float c = 0.3f;
System.out.println(c == (a + b));
System.out.println(0.3f == (a + b));
int a = 0;
int b = 0;
System.out.println(a/b);
double a = 0d;
double b = 0d;
System.out.println(a/b);
这里面有太多的我们初始学习时就遇到过的,有的遇到过的不止一遍,面试问到的也不止一遍,为什么到现在,我们还有些题目模棱两可呢,为什么不抽点时间好好看看这方面的知识呢?今天把答案公布下,看看自己对了几个,后续文章会一点点解释每个题目的,请关注置顶公众号。
true
true
true
true
true
true
true
true
true
false
true
true
false
true
false
true
true
false
true
false
true
true
false
true
false
false
false
true
true
java.lang.ArithmeticException: / by zero
NaN
专注于Java干货享
扫描二维码
获取Java干货
点个在看少个bug
评论