packageoperator;/**
* @author 喵喵
*/publicclassDemo01{publicstaticvoidmain(String[] args){//二元运算符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);}}
关系运算符
packageoperator;/**
* @author 喵喵
*/publicclassDemo02{publicstaticvoidmain(String[] args){//关系运算符返回的结果;布尔值(true,false)int a =10;int b =20;System.out.println(a>b);System.out.println(a<b);System.out.println(a==b);System.out.println(a!=b);}}
一元运算符
packageoperator;/**
* @author 喵喵
*/publicclassDemo03{publicstaticvoidmain(String[] args){//++ 自增 --自减 一元运算符int a =5;//执行完这个int d = a++后,先给d赋值,再自增int d =a++;//后面的a=a+1System.out.println(a);//在执行这int c = ++a前,先自增,再给c赋值int c =++a;System.out.println(a);System.out.println(d);System.out.println(c);}}
与, 或 ,非, 运算
packageoperator;/**
* @author 喵喵
*/publicclassDemo04{publicstaticvoidmain(String[] args){//逻辑运算 与(and) 或(or) 非(取反)boolean a =true;boolean b =false;//逻辑与运算;两个变量都为真,结果才为true。System.out.println("a&&b;"+(a&&b));//逻辑或运算;两个变量有一个为真,则结果才为true。System.out.println("a||b;"+(a||b ));//逻辑非运算;如果为假则为真,如果是假则为真。System.out.println("!(a&&b);"+!(a&&b));//短路运算int c =6;//与运算boolean d =(c<4)&&(c++<9);System.out.println(d);//输出的c=6 因为c<3为false 后面的c++不会被执行System.out.println(c);}}