Java基础知识

1
2
3
4
5
>> 带符号右移。正数右移高位补0,负数右移高位补1。比如:  
4 >> 1,结果是2-4 >> 1,结果是-2-2 >> 1,结果是-1
>>> 无符号右移。无论是正数还是负数,高位通通补0
对于正数而言,>>和>>>没区别。
对于负数而言,-2 >>> 1,结果是 2147483647(Integer.MAX_VALUE),-1 >>> 1,结果是 2147483647(Integer.MAX_VALUE)。

for循环的过程和顺序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class Main {

private static int index = -1 ;

public static int init(int arg){
System.out.println("init");
return arg;
}

public static boolean judge(int arg){
System.out.println("judge");
return arg < 3;
}

public static void step(){
index++;
System.out.println("step , index is "+ index);
}

public static void main(String[] args){

for( index = init(0) ; judge(index) ; step()){
System.out.println("in for body index is " + index);
}
}
}
以下是输出结果:
init
judge
in for body index is 0
step , index is 1
judge
in for body index is 1
step , index is 2
judge
in for body index is 2
step , index is 3
judge