packageoperator;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;publicclassDemo02{publicstaticvoidmain(String[] args){long a =1233335461l;int b =12345;short c =10;byte d =8;System.out.println(a+b+c+d);//LongSystem.out.println(b+c+d);//IntSystem.out.println(c+d);//Int}}
packageoperator;publicclassDemo03{publicstaticvoidmain(String[] args){//关系运算符返回的结果:正确 错误,布尔值int a =10;int b =20;int c =22;System.out.println(c%a);//取余(模运算)System.out.println(a>b);System.out.println(a<b);System.out.println(a==b);System.out.println(a!=b);}}
自增自减运算,Math类
packageoperator;publicclassDemo04{publicstaticvoidmain(String[] args){//++(自增) --(自减) 一元运算符int a =3;int b = a++;//执行完这行代码后,先给b赋值,再自增//a = a + 1;System.out.println(a);//a = a + 1;int c =++a;//执行完这行代码前,先自增,再给c赋值System.out.println(a);System.out.println(b);System.out.println(c);//幂运算 2^3double pow =Math.pow(2,3);System.out.println(pow);}}
逻辑运算符,位运算符
packageoperator;//逻辑运算符publicclassDemo05{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);System.out.println(d);System.out.println(c);}}
packageoperator;//三元运算符publicclassDemo08{publicstaticvoidmain(String[] args){// x ? y : z//如果x==true,则结果为y,否则结果为zint score =80;String type = score <60?"不及格":"及格";//必须掌握//ifSystem.out.println(type);}}