Java 语言支持如下 运算符:
算数运算符: + - * / % ++ –
package operator; /** * Created by JKK on 2021/6/19. */ 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(a/(double)b); } }
赋值运算符: =
关系运算符: > < <= >= == != instanceof
package operator; /** * Created by JKK on 2021/6/19. */ public class Demo03 { public static void main(String[] args) { //关系运算符返回的 结果:正确,错误 布尔值 int a=2; int b=3; int c=3; System.out.println(a>b);//输出false错 System.out.println(a<c);//输出true System.out.println(b==c);//输出true对 System.out.println(a!=b); System.out.println(c%a);//取余数 } }
逻辑运算符: &&(and;与,和) ||(或;or) !(否)
位运算符:& | ~ >> << >>>
条件运算符:? :
扩展赋值运算符:+= -= *= /=