`

埃森哲面试一小部分题目,位运算

 
阅读更多
第一道:
public static void main(String[] args) {
    System.out.println(test1());
}
public static String test1(){
    try{
       return "aaa";
    }finally{
       System.out.println("ttt");
    }
}
第二道:(位运算符,考点涉及到 ">>" 和 ">>>" )
  eg1: 128>>>1 结果是64
  128 = 0 1 0 0 0 0 0 0 0,此时进行逻辑右移1位,结果是0 0 1 0 0 0 0 0 0 = 64
  >> 和 >>> 的区别是:>>需要判断位移的数是否为负数,若负数则在二进制数前面+1,而非0.
  eg2: -12>>2
  -12 = 1 1 1 0 1 0 0(换算过程:12=0001100,求反+1得到-12=1110100)
  1 1 1 0 1 0 0进行算术右移2位,得到1111101
  1111101 换算成int类型的数字则是 将其-1再求反得到2, 即1111101为-2

第三道:switch(param){ }  param的基本数据类型可以为: byte int short long char,由于byte short long char转换为int不损失精度,而float和double则不行。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics