1、算术运算符

  • +:加法
  • -:减法
  • *:乘法
  • /:除法取商
  • %:取余取模
  • ++:自增运算符
  • i++:先使用i的值,再对i做增1的操作
  • ++i:先对i做增1的操作,再使用i的值
  • —:自减运算符
  • i—:先使用i的值,再对i做减1的操作
  • —i:先对i做减1的操作,再使用i的值 ``` int a = 6; int b = 4; System.out.println(a*1.0/b);//1.5 整型和浮点型的结果是浮点型 System.out.println(a/b);//1

System.out.println(a);//6 System.out.println(a++);//6 System.out.println(a);//7

System.out.println(b);//4 System.out.println(++b);//5 System.out.println(b++);//5

  1. <a name="wtNd7"></a>
  2. ### 2、关系运算符
  3. ![image.png](https://cdn.nlark.com/yuque/0/2021/png/503653/1638685600169-deb82d7e-6f78-46f9-8a76-907864581852.png#clientId=u0949ec97-fc23-4&from=paste&height=283&id=uc1af91be&margin=%5Bobject%20Object%5D&name=image.png&originHeight=283&originWidth=500&originalType=binary&ratio=1&size=182106&status=done&style=none&taskId=u371d77a3-bcaa-4580-a76f-b138bd8e60c&width=500)
  4. <a name="nett5"></a>
  5. ### 3、逻辑运算符
  6. ![image.png](https://cdn.nlark.com/yuque/0/2021/png/503653/1638685610701-0d3d924f-c9fd-4db4-bc3a-f69035aa81ee.png#clientId=u0949ec97-fc23-4&from=paste&id=ub5cec5ba&margin=%5Bobject%20Object%5D&name=image.png&originHeight=261&originWidth=685&originalType=url&ratio=1&size=193129&status=done&style=none&taskId=u3d9d6d3e-0a97-4050-91e9-14d03f8a8b9)
  7. - &&:第一个为false,右边就不计算了,直接返回false ;
  8. - &:不管如何左右都计算
  9. - || :第一个为true 右边就不计算了,直接返回true;
  10. - | :不管如何左右都计算
  11. <a name="bIrGA"></a>
  12. ### 4、赋值运算符
  13. ![image.png](https://cdn.nlark.com/yuque/0/2021/png/503653/1638685680843-811736bb-d8d4-4ab3-a90f-5ba7543ea392.png#clientId=u0949ec97-fc23-4&from=paste&id=uc49825af&margin=%5Bobject%20Object%5D&name=image.png&originHeight=281&originWidth=458&originalType=url&ratio=1&size=152785&status=done&style=none&taskId=u3c9f92f1-ef6a-4c56-9116-79269a0eac5)
  14. <a name="kuspO"></a>
  15. ### 5、移位运算符
  16. - <<:向左移位(a<<3左移3位,低位补0,扩大2^3倍)
  17. - >>:带符号向右移位(a>>3右移3位,高位补原符号位,缩小2^3倍)
  18. - >>>:无符号向右移位(a>>>3右移3位,高位补0,缩小2^3倍)
  19. ![image.png](https://cdn.nlark.com/yuque/0/2021/png/503653/1638685756333-8bb7a759-553c-4820-9e44-6892ceee8a4b.png#clientId=u0949ec97-fc23-4&from=paste&id=u84b278bf&margin=%5Bobject%20Object%5D&name=image.png&originHeight=156&originWidth=554&originalType=url&ratio=1&size=107469&status=done&style=none&taskId=ue6dd8da2-f2d1-48d1-b42e-c5b644f0300)<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/503653/1638685756344-ab1e4bc1-a8f7-4dce-a482-a94cd41352e2.png#clientId=u0949ec97-fc23-4&from=paste&id=u17bc34dc&margin=%5Bobject%20Object%5D&name=image.png&originHeight=160&originWidth=550&originalType=url&ratio=1&size=102510&status=done&style=none&taskId=u2707a7a9-5bb0-4330-949c-a9d2837b4a5)
  20. <a name="QBK9u"></a>
  21. ### 6、位运算符(二进制位进行运算)
  22. ![image.png](https://cdn.nlark.com/yuque/0/2021/png/503653/1638685885713-a19e0c94-e5fb-4bc7-a686-ec109da5579f.png#clientId=u0949ec97-fc23-4&from=paste&id=ua0c0c760&margin=%5Bobject%20Object%5D&name=image.png&originHeight=389&originWidth=438&originalType=url&ratio=1&size=161929&status=done&style=none&taskId=uaa780e1e-53d2-4123-a06e-01a7aa79a8e)
  23. <a name="Ssxg3"></a>
  24. ### 7、条件运算符:三目运算符
  25. - 表达式1?表达式2:表达式3

int aa = 25; int bb = 44;

int result = aa>bb?aa:bb; ```

8、运算符的优先级

  • 优先级比较复杂,直接加()解决优先级问题

image.png