packageoperator;publicclassDemo01{publicstaticvoidmain(String[] args){//二元运算符int a =6;int b =5;int c =5;int d =2;System.out.println(a+b);System.out.println(a*b);System.out.println(a-b);System.out.println(a/(double)b);System.out.println("==========================");long e =366235565561212155L;int r=123;short t =10;byte g =8;System.out.println(e+r+t+g);//longSystem.out.println(r+t+g);//intSystem.out.println(t+g);//intSystem.out.println("==========================");//++ -- 自增 自减 一元运算符int h =3;int k = h++;//执行代码后,先赋值,再自增System.out.println(h);//a++是先赋值,再自增int f =++h;//执行代码前,先自增,再赋值System.out.println(h);System.out.println(k);System.out.println(f);//幂运算 2^3 2*2*2=8 很多运算,我们会使用一些工具类来操作!double pow=Math.pow(2,3);System.out.println(pow);}}
赋值运算符:=
关系运算符:> < >= <= == != instanceof
packageoperator;publicclassDemo06{publicstaticvoidmain(String[] args){//关系运算符返回结果 正确,错误, 布尔值int a =10;int b =20;int c =22;System.out.println(a>b);System.out.println(a<b);System.out.println(a==b);System.out.println(a!=b);System.out.println(c % a);}}
逻辑运算符:&& || !
packageoperator;publicclassDemo02{publicstaticvoidmain(String[] args){//逻辑运算符//与(and) 或(or) 非(取反)boolean a =true;boolean b =false;System.out.println("a && b:"+(a && b));//逻辑与,两个都为真,结果为trueSystem.out.println("a || b:"+(a || b));//逻辑或,一个为真,结果为就是trueSystem.out.println("!(a && b):"+!(a && b));//逻辑非,如果是真变为假,反之一样//短路运算int c =5;boolean d =(c<4&&(c++<4));//c<4是false后面就不执行了System.out.println(d);System.out.println(c);}}