算数运算符:+,-,*,/,%(取余),++,--
赋值运算符:=
关系运算符:<, >, >= ,<= ,== , !=
逻辑运算符:&&,||,!
位运算符:&,|,^,~,>>,<<
条件运算符:?,:
扩展赋值运算符:+=,-=,*=,/=
public class Demo01 { public static void main(String[] args) { // 二元运算符 //ctrl+D : 复制当前行到下一行 int a = 10; int b = 20; int c = 25; int d = 25; System.out.println(a+b); System.out.println(a-b); System.out.println(a*b); System.out.println(c/(double)a); //相当于求精确值(2.5),结果的数据类型为double System.out.println(c/a); //相当于取整(2),结果的数据类型仍为int } } public class Demo02 { public static void main(String[] args) { long a = 123123123123123L; int b = 123; short c = 10; byte d = 8; System.out.println(a+b+c+d); //long System.out.println((b+c+d)); //int System.out.println(c+d); //int } } public class Demo03 { public static void main(String[] args) { // 关系运算符号的返回的结果: int a = 10; int b = 20; int c = 21; System.out.println(c%a);// 取余 取模 System.out.println(c/a); System.out.println(c/(double)a); System.out.println(a>b); System.out.println(a<b); System.out.println(a==b); System.out.println(a!=b); } } public class Demo04 { public static void main(String[] args) { //++ -- 一元运算符 int a = 3; int b = a++; System.out.println(a); int c = ++a; System.out.println(a); System.out.println(b); System.out.println(c); // 幂运算 double pow = Math.pow(2, 3); System.out.println(pow); System.out.println("============"); int d = 5; boolean e =(d<4) && (d++<4); //d++,在程序中没有执行,所以d的值没有没变化 System.out.println(e); System.out.println(d); } } public class Demo05 { 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*8的计算效率最高。2*8=2*2*2*2 0000 0001 0010 0100 1000 0000 对一个数而言,左移相当于*2; 右移相当于/2 */ System.out.println(2<<3); System.out.println(3>>1); } } public class Demo06 { public static void main(String[] args) { int a = 10; int b = 20; a+=b; System.out.println(a); //a-=b; //System.out.println(a); //字符连接号 + ,当+前面有字符时,当连接号用,+前面无字符时,当计算符号+用。 System.out.println(a+b+""); System.out.println(""+a+b); } }