短路运算:
public class Annotation {
public static void main(String[] args) {
int a = 5;
boolean b = (a<4)&&(a++<5);//a<4已经成立,a++<5根本不
//用再算了
System.out.println(b);
System.out.println(a);
}
}
输出结果:
false
5
位运算:
&、|、^、~、<<、>>:
A = 0011 1100
B = 0000 1101
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 1110
~B = 1111 0010
public class Annotation {
public static void main(String[] args) {
int A = 1;
System.out.println(A<<3);
}
}
输出:
8
原因:A:0000 0001 左移三位→0000 1000
<<:*2
>>:/2
public class Annotation {
public static void main(String[] args) {
int A = 3;
System.out.println(A<<3);
}
}
输出:
24
字符串连接符:
public class Annotation {
public static void main(String[] args) {
int A = 3;
int B = 4;
System.out.println(A+B+"");
System.out.println(""+A+B);
}
}
输出:
7
34
public class Annotation {
public static void main(String[] args) {
int A = 3;
int B = 4;
String type = A>B?"A>B":"A<B";
System.out.println(type);
}
}
输出:
A<B
原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/245315.html