运算符
自增自减
public class Demo02 {
public static void main(String[] args) {
int a = 3;
int b = a++;
// a = a + 1
// a = a + 1
int c = ++a;
System.out.println(a); //5
System.out.println(b); //3
System.out.println(c); //5
}
}
逻辑运算
public class Demo03 {
public static void main(String[] args) {
boolean a = true;
boolean b = false;
System.out.println(a&&b); //false
System.out.println(a||b); //true
System.out.println(!(a&&b)); //true
}
}
位运算
A = 0011 1100
B = 0000 1101
A&B : 0000 1100
A|B : 0011 1101
A^B : 0011 0001 (相同为0, 不相同为1)
~B : 1111 0010 (取反)
public class Demo03 {
public static void main(String[] args) {
// 位运算
/*
--------------------------
2*8 = 16 怎么算最快?
<< : *2
>> : /2
效率高
2: 0000 0010
16: 0001 0000
*/
System.out.println(2<<3); //16
}
}
拓展
public class Demo04 {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(""+a+b); //1020
System.out.println(a+b+""); //30
}
}