复制代码
- //:AllOps.java
- //Testsalltheoperatorsonallthe
- //primitivedatatypestoshowwhich
- //onesareacceptedbytheJavacompiler.
- classAllOps{
- //Toaccepttheresultsofabooleantest:
- voidf(booleanb){}
- voidboolTest(booleanx,booleany){
- //Arithmeticoperators:
- //!x=x*y;
- //!x=x/y;
- //!x=x%y;
- //!x=x+y;
- //!x=x-y;
- //!x++;
- //!x--;
- //!x=+y;
- //!x=-y;
- //Relationalandlogical:
- //!f(x>y);
- //!f(x>=y);
- //!f(x<y);
- //!f(x<=y);
- f(x==y);
- f(x!=y);
- f(!y);
- x=x&&y;
- x=x||y;
- //Bitwiseoperators:
- //!x=~y;
- x=x&y;
- x=x|y;
- x=x^y;
- //!x=x<<1;
- //!x=x>>1;
- //!x=x>>>1;
- //Compoundassignment:
- //!x+=y;
- //!x-=y;
- //!x*=y;
- //!x/=y;
- //!x%=y;
- //!x<<=1;
- //!x>>=1;
- //!x>>>=1;
- x&=y;
- x^=y;
- x|=y;
- //Casting:
- //!charc=(char)x;
- //!byteB=(byte)x;
- //!shorts=(short)x;
- //!inti=(int)x;
- //!longl=(long)x;
- //!floatf=(float)x;
- //!doubled=(double)x;
- }
- voidcharTest(charx,chary){
- //Arithmeticoperators:
- 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;
- //Relationalandlogical:
- f(x>y);
- f(x>=y);
- f(x<y);
- f(x<=y);
- f(x==y);
- f(x!=y);
- //!f(!x);
- //!f(x&&y);
- //!f(x||y);
- //Bitwiseoperators:
- 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);
- //Compoundassignment:
- x+=y;
- x-=y;
- x*=y;
- x/=y;
- x%=y;
- x<<=1;
- x>>=1;
- x>>>=1;
- x&=y;
- x^=y;
- x|=y;
- //Casting:
- //!booleanb=(boolean)x;
- byteB=(byte)x;
- shorts=(short)x;
- inti=(int)x;
- longl=(long)x;
- floatf=(float)x;
- doubled=(double)x;
- }
- voidbyteTest(bytex,bytey){
- //Arithmeticoperators:
- x=(byte)(x*y);
- x=(byte)(x/y);
- x=(byte)(x%y);
- x=(byte)(x+y);
- x=(byte)(x-y);
- x++;
- x--;
- x=(byte)+y;
- x=(byte)-y;
- //Relationalandlogical:
- f(x>y);
- f(x>=y);
- f(x<y);
- f(x<=y);
- f(x==y);
- f(x!=y);
- //!f(!x);
- //!f(x&&y);
- //!f(x||y);
- //Bitwiseoperators:
- x=(byte)~y;
- x=(byte)(x&y);
- x=(byte)(x|y);
- x=(byte)(x^y);
- x=(byte)(x<<1);
- x=(byte)(x>>1);
- x=(byte)(x>>>1);
- //Compoundassignment:
- x+=y;
- x-=y;
- x*=y;
- x/=y;
- x%=y;
- x<<=1;
- x>>=1;
- x>>>=1;
- x&=y;
- x^=y;
- x|=y;
- //Casting:
- //!booleanb=(boolean)x;
- charc=(char)x;
- shorts=(short)x;
- inti=(int)x;
- longl=(long)x;
- floatf=(float)x;
- doubled=(double)x;
- }
- voidshortTest(shortx,shorty){
- //Arithmeticoperators:
- x=(short)(x*y);
- x=(short)(x/y);
- x=(short)(x%y);
- x=(short)(x+y);
- x=(short)(x-y);
- x++;
- x--;
- x=(short)+y;
- x=(short)-y;
- //Relationalandlogical:
- f(x>y);
- f(x>=y);
- f(x<y);
- f(x<=y);
- f(x==y);
- f(x!=y);
- //!f(!x);
- //!f(x&&y);
- //!f(x||y);
- //Bitwiseoperators:
- x=(short)~y;
- x=(short)(x&y);
- x=(short)(x|y);
- x=(short)(x^y);
- x=(short)(x<<1);
- x=(short)(x>>1);
- x=(short)(x>>>1);
- //Compoundassignment:
- x+=y;
- x-=y;
- x*=y;
- x/=y;
- x%=y;
- x<<=1;
- x>>=1;
- x>>>=1;
- x&=y;
- x^=y;
- x|=y;
- //Casting:
- //!booleanb=(boolean)x;
- charc=(char)x;
- byteB=(byte)x;
- inti=(int)x;
- longl=(long)x;
- floatf=(float)x;
- doubled=(double)x;
- }
- voidintTest(intx,inty){
- //Arithmeticoperators:
- x=x*y;
- x=x/y;
- x=x%y;
- x=x+y;
- x=x-y;
- x++;
- x--;
- x=+y;
- x=-y;
- //Relationalandlogical:
- f(x>y);
- f(x>=y);
- f(x<y);
- f(x<=y);
- f(x==y);
- f(x!=y);
- //!f(!x);
- //!f(x&&y);
- //!f(x||y);
- //Bitwiseoperators:
- x=~y;
- x=x&y;
- x=x|y;
- x=x^y;
- x=x<<1;
- x=x>>1;
- x=x>>>1;
- //Compoundassignment:
- x+=y;
- x-=y;
- x*=y;
- x/=y;
- x%=y;
- x<<=1;
- x>>=1;
- x>>>=1;
- x&=y;
- x^=y;
- x|=y;
- //Casting:
- //!booleanb=(boolean)x;
- charc=(char)x;
- byteB=(byte)x;
- shorts=(short)x;
- longl=(long)x;
- floatf=(float)x;
- doubled=(double)x;
- }
- voidlongTest(longx,longy){
- //Arithmeticoperators:
- x=x*y;
- x=x/y;
- x=x%y;
- x=x+y;
- x=x-y;
- x++;
- x--;
- x=+y;
- x=-y;
- //Relationalandlogical:
- f(x>y);
- f(x>=y);
- f(x<y);
- f(x<=y);
- f(x==y);
- f(x!=y);
- //!f(!x);
- //!f(x&&y);
- //!f(x||y);
- //Bitwiseoperators:
- x=~y;
- x=x&y;
- x=x|y;
- x=x^y;
- x=x<<1;
- x=x>>1;
- x=x>>>1;
- //Compoundassignment:
- x+=y;
- x-=y;
- x*=y;
- x/=y;
- x%=y;
- x<<=1;
- x>>=1;
- x>>>=1;
- x&=y;
- x^=y;
- x|=y;
- //Casting:
- //!booleanb=(boolean)x;
- charc=(char)x;
- byteB=(byte)x;
- shorts=(short)x;
- inti=(int)x;
- floatf=(float)x;
- doubled=(double)x;
- }
- voidfloatTest(floatx,floaty){
- //Arithmeticoperators:
- x=x*y;
- x=x/y;
- x=x%y;
- x=x+y;
- x=x-y;
- x++;
- x--;
- x=+y;
- x=-y;
- //Relationalandlogical:
- f(x>y);
- f(x>=y);
- f(x<y);
- f(x<=y);
- f(x==y);
- f(x!=y);
- //!f(!x);
- //!f(x&&y);
- //!f(x||y);
- //Bitwiseoperators:
- //!x=~y;
- //!x=x&y;
- //!x=x|y;
- //!x=x^y;
- //!x=x<<1;
- //!x=x>>1;
- //!x=x>>>1;
- //Compoundassignment:
- x+=y;
- x-=y;
- x*=y;
- x/=y;
- x%=y;
- //!x<<=1;
- //!x>>=1;
- //!x>>>=1;
- //!x&=y;
- //!x^=y;
- //!x|=y;
- //Casting:
- //!booleanb=(boolean)x;
- charc=(char)x;
- byteB=(byte)x;
- shorts=(short)x;
- inti=(int)x;
- longl=(long)x;
- doubled=(double)x;
- }
- voiddoubleTest(doublex,doubley){
- //Arithmeticoperators:
- x=x*y;
- x=x/y;
- x=x%y;
- x=x+y;
- x=x-y;
- x++;
- x--;
- x=+y;
- x=-y;
- //Relationalandlogical:
- f(x>y);
- f(x>=y);
- f(x<y);
- f(x<=y);
- f(x==y);
- f(x!=y);
- //!f(!x);
- //!f(x&&y);
- //!f(x||y);
- //Bitwiseoperators:
- //!x=~y;
- //!x=x&y;
- //!x=x|y;
- //!x=x^y;
- //!x=x<<1;
- //!x=x>>1;
- //!x=x>>>1;
- //Compoundassignment:
- x+=y;
- x-=y;
- x*=y;
- x/=y;
- x%=y;
- //!x<<=1;
- //!x>>=1;
- //!x>>>=1;
- //!x&=y;
- //!x^=y;
- //!x|=y;
- //Casting:
- //!booleanb=(boolean)x;
- charc=(char)x;
- byteB=(byte)x;
- shorts=(short)x;
- inti=(int)x;
- longl=(long)x;
- floatf=(float)x;
- }
- }///:~
复制代码
- //:Overflow.java
- //Surprise!Javaletsyouoverflow.
- publicclassOverflow{
- publicstaticvoidmain(String[]args){
- intbig=0x7fffffff;//maxintvalue
- prt("big="+big);
- intbigger=big*4;
- prt("bigger="+bigger);
- }
- staticvoidprt(Strings){
- System.out.println(s);
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |