您的位置:首页 > 编程语言 > PHP开发

scjp题目解析(八)

2008-07-28 22:15 344 查看
  public class Happy {
public static void main(String args[]) {
int i=4;
int j=2;
methodA(i,j);
System.out.println(i);
}
static public void methodA(int i,int j) {
i<<=j;
}
}
What will be the output ?
a) compilation error
b) 16
c) 64
d) 4
f) runtime exception

以下题目写个程序来测试一下

public class Eddy {
 public static void main(String args[]){
 int i=4;
 int j=2;
 methodA(i,j);
 System.out.println(i);
 }
 static public void methodA(int i,int j) {
 i<<=j;
 }

}

解析如下:

首先把4化成二进制数

4/2=2  0
2/2=1  0

100左移两位就是10000=(decimal)16

i<<=j然后把16重新赋值给j(注意:这里的<<=意思是左移完之后把值赋给j =是赋值操作符==是等于操作符)

而这里的i却一直没有变

Therefore, this issue is the result of:
D:

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息