版权声明:本文为博主原创文章,转载请说明出处。
All operators
package AllOps;
public class AllOperators {
void f(boolean b){}
void boolTest(boolean x,boolean y){
f(x==y);
f(x!=y);
f(!y); //非运算
x=x&&y; //与运算
x=x||y; //或运算
x=x|y;
x=x^y;
x&=y; //按位与
x^=y; //按位异或
x|=y; //按位或
}
void charTest(char x,char y){
x=(char)(x%y);
x=(char)(x/y);
x=(char)(x*y);
x=(char)(x-y);
x=(char)(x+y);
x++;
x--;
x=(char)+y;
x=(char)-y;
f(x>y);
f(x>=y);
f(x<y);
f(x<=y);
f(x==y);
f(x!=y);
x=(char)~y;
x=(char)(x&y);
x=(char)(x|y);
x=(char)(x^y);
x=(char)(x<<1);
x=(char)(x>>1);
x=(char)(x>>>1);
x+=y; //链接不同的字符串 ,操作符重载
x-=y;
x*=y;
x/=y;
x%=y;
x<<=1;
x>>=1;
x>>>=1;
x&=y;
x^=y;
x|=y;
char c=(char)x;
byte b=(byte)x;
short s=(short)x;
long l=(long)x;
double d=(double)x;
}
void LongTest(long x,long y){
x=x*y;
x=x-y;
x=x+y;
x=x%y;
x=x/y;
x++; //后缀递增,先生成值,再执行预算
x--;
x=+y;
x=-y;
f(x>=y); //大于等于
f(x>y);
f(x<y);
f(x<=y);
f(x==y);
f(x!=y);
x=~y; //按位非
x=x&y;
x=x^y;
x=x|y;
x=x<<1; //x左移位1,将得到结果返回x
x=x>>1;
x=x>>>1;
x+=y; //将x加y,并将结果返回给x
x-=y;
x*=y;
x/=y;
x%=y;
x<<=1;
x>>=1;
x>>>=1;
x&=y;
x|=y;
x^=y;
}
}
Attention
1.优先级
2.赋值
3.算数运算符
4.自动递增和递减
5.关系操作符
6.逻辑操作符
7.java没有sizeof