先贴出一道最近去某公司的面试题,不知道出自哪里?有哪位见多识广的仁兄可以告知一声,不胜感激!
public class test (
2. public static void main (String args[]) {
3. int i = 0xFFFFFFF1;
4. int j = ~i;
5.
6. }
7. )
What is the decimal value of j at line 5?
A. 0
B. 1
C. 14
D. –15
E. An error at line 3 causes compilation to fail.
F. An error at line 4 causes compilation to fail.
Answer: C
选项是英文给我的印象很深,让我一下子穿越到了英语四级的考试现场,让我赶紧画一些关键字~~
![得意](http://static.blog.csdn.net/xheditor/xheditor_emot/default/proud.gif)
大家是不是开始在草稿纸上算起来了,大家可以先猜猜是什么答案!反正这道题我是选的E、F,题目要求也没有要求是单选。。
结果,结果我就悲剧了,回来立马运行了下面的程序,事实胜于雄辩!
class Test{
public static void main(String args[]){
int i=0xFFFFFFF1;
int j=~i;
int max = Integer.MAX_VALUE ;
int min = Integer.MIN_VALUE ;
System.out.println("int i value= " + i +
" hex value " + Integer.toHexString(i) );
System.out.println("int j value= " + j +
" hex value " + Integer.toHexString(j) );
System.out.println("Integer.MAX_VALUE= " +Integer.MAX_VALUE +
" hex value " + Integer.toHexString(Integer.MAX_VALUE ) );
System.out.println("Integer.MIN_VALUE= " + Integer.MIN_VALUE +
" hex value " + Integer.toHexString(Integer.MIN_VALUE ) );
}
}
输出结果:
好了,看到输出的那一刻,才发现我的答案应该是什么了!
Tips:遇到拿不准的问题,最好的解决途径就是上手调试,这样你会马上得到答案!