自增自减运算符
package operater;
public class demo04 {
public static void main(String[] args) {
int a=20;
int b=a++;//a先给b赋值,然后再自增
System.out.println(a);//21
System.out.println(b);//20
System.out.println("===========================");
int c=100;
int d=++c;//c先自增,然后再给d赋值
System.out.println(c);//101
System.out.println(d);//101
}
}
位运算符
package operater;
public class demo06 {
public static void main(String[] args) {
/*
A = 0011 1100
B = 0000 1101
-------------
A&B = 0000 1100 与
A|B = 0011 1101 或
A^B = 0011 0001 异或
~B = 1111 0010 非
-------------
<< *2
>> /2
*/
}
}
三元运算符
- 格式: x ? y : z
- 解读:如果x为true,则结果为y,否则结果为z
package operater;
public class demo08 {
public static void main(String[] args) {
// x ? y : z
//如果x为true,则结果为y,否则结果为z
int score = 56;
String type = score < 60 ? "不及格" : "及格";
//如果分数小于60则不及格,否则就为及格
System.out.println(type);
}
}
拼接运算
package operater;
public class demo07 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a += b;//a=a+b
System.out.println(a);
a -= b;//a=a-b
System.out.println(a);
//字符串连接符 +,String
System.out.println(a + b);//30
System.out.println("" + a + b);//1020,直接以字符串的形式相拼接
System.out.println(a + b + "");//30,先计算a+b的值,再拼接字符串
}
}