有时候觉得自己对简单的知识了如指掌,这让我想起了2012年安徽的高考数学,当学生们考完数学出来时都兴高采烈的出了教室门,因为那年的数学卷子是有史以来感觉最简单的,当成绩出来傻了一片人,好多数学成绩原本好的才刚刚及格。起始都掉进了题目的陷阱里去了。而下面的文章,也是和数学题目差不多,很多陷阱,不信你来看看!!! **下面的输出结果是什么?**
问题一:
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