⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 allops.java

📁 java编程思想的部分实现
💻 JAVA
字号:
//:c3:Allops.java
//Tests all the operators on all the primitive data types to show which ones are accepted by //the java compilier
class Allops
{
	//To accept the results of a boolean test:
	void f(boolean b){}
	void boolTest(boolean x,boolean y)
	{
		//Arithmetic operators:
		//!x=x*y;
		//!x=x/y;
		//!x=x%y;
		//!x=x+y;
		//!x=x-y;
		//!x++;
		//!x--;
		//!x=+y;
		//!x=-y;
		//Relational and logocal:
		//!f(x>y);
		//!f(x>=y);
		//!f(x<=y);
		//!f(x<y);
		f(x==y);
		f(x!=y);
		f(!x);
		x=x&&y;
		x=x||y;
		//bitwise operators:
		//!x=-y;
		x=x&y;
		x=x|y;
		x=x^y;
		//!x=x<<1;
		//!x=x>>1;
		//!x=x>>>1;
		//compound assighment:
		//!x+=y;
		//!x-=y;
		//!x*=y;
		//!x/=y;
		//!x%=y;
		//!x<<=1;
		//!x>>=1;
		//!x>>>=1;
		x^=y;
		x&=y;
		x|=y;
		//Castiflg:
		//!char c=(char)x;
		//!byte b=(byte)x;
		//!short s=(short)x;
		//!int i=(int)x;
		//!long l=(long)x;
		//!float f=(float)x;
		//!double d=(double)x;
	}
	void charTest(char x,char y)
	{
		//Arithmetic operators:
		x=(char)(x*y);
		x=(char)(x/y);
		x=(char)(x%y);
		x=(chr)(x+y);
		x=(char)(x-y);
		x++;
		x--;
		x=(char)+y;
		x=(char)-y;
		//Relational and logical
		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);
		//Bitwise operators:
		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);
		//compound assignment:
		x+=y;
		x-=y;
		x*=y;
		x/=y;
		x%=y;
		x<<=1;
		x>>=1;
		x>>>=1;
		x&=y;
		x^=y;
		x|=y;
		//casting:
		//!boolean b=(boolean)x;
		byte b=(byte)x;
		short s=(short)x;
		int i=(int)x;
		long l=(long)x;
		float f=(float)x;
		double d=(double)x;
	}
	void byteTest(byte x,byte y)
	{
		//Arithmetic operators:
		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;
		//Ralational and logical:
		f(x>y);
		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);
		//bitwise operators:
		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);
		//Compound assighnment:
		x+=y;
		x-=y;
		x*=y;
		x/=y;
		x%=y;
		x<<=1;
		x>>=1;
		x>>>=1;
		x&=y;
		x|=y;
		//casting:
		//!boolean b=(boolean)x;
		char c=(char)x;
		short s=(short)x;
		long l=(long)x;
		int i=(int)x;
		float f=(float)x;
		double d=(double)x;
	}
	
	void shortTest(short x,short y)
	{
		//Arithmetic operator:
		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;
		//Relational and logical;
		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);
		//bitwise operators:
		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);
		//compound assighment:
		x+=y;
		x-=y;
		x*=y;
		x/=y;
		x%=y;
		x<<=1;
		x>>=1;
		x>>>=1;
		x&=y;
		x^=y;
		x|=y;
		//casting:
		//!boolean b=(boolean)x;
		char c=(char)x;
		byte b=(byte)x;
		int i=(int)x;
		long l=(long)x;
		float f=(float)x;
		double d=(double)x;
	}
	
	void intTest(int x,int y)
	{
		//Arithmatic operators:
		x=x*y;
		x=x/y;
		x=x%y;
		x=x+y;
		x=x-y;
		x++;
		x--;
		x=+y;
		x=-y;
		//ralational and logicl:
		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);
		//bitwise operators:
		x=~y;
		x=x&y;
		x=x|y;
		x=x^y;
		x=x<<1;
		x=x>>1;
		x=x>>>1;
		//compound assignment:
		x+=y;
		x-=y;
		x*=y;
		x/=y;
		x%=y;
		x<<=1;
		x>>=1;
		x>>>=1;
		x&=y;
		x^=y;
		x|=y;
		//casting:
		//!boolean b=(boolean)x;
		char c=(char)x;
		byte b=(byte)x;
		short s=(short)x;
		long l=(long)x;
		float f=(float)x;
		double d=(double)x;
	}
	
	void longTest(long x,long y)
	{
		//Arithmetic:
		x=x*y;
		x=x/y;
		x=x%y;
		x=x+y;
		x=x-y;
		x++;
		x--;
		x=+y;
		x=-y;
		//Relational and logical:
		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);
		//bitewise operators:
		x=~y;
		x=x&y;
		x=x|y;
		x=x^y;
		x=x<<1;
		x=x>>1;
		x=x>>>1;
		//compound assignment:
		x+=y;
		x-=y;
		x*=y;
		x/=y;
		x%=y;
		x<<=1;
		x>>=1;
		x>>>=1;
		x&=y;
		x^=y;
		x|=y;
		//casting:
		//!boolean b=(boolean)x;
		char c=(char)x;
		byte b=(byte)x;
		short s=(short)x;
		int i=(int)x;
		float f=(float)x;
		double d=(double)x;
	}
	
	void floatTest(float x,float y)
	{
		//Arithmetic operators:
		x=x*y;
		x=x/y;
		x=x%y;
		x=x+y;
		x=x-y;
		x++;
		x--;
		x=+y;
		x=-y;
		x=*y;
		x=/y;
		x=%y;
		//relational and logical:
		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);
		//bitwise operators:
		//!x=~y;
		//!x=x&y;
		//!x=x|y;
		//!x=x^y;
		//!x=x>>1;
		//!x=x<<1;
		//!x=x>>>1;
		//compound assignment:
		x+=y;
		x-=y;
		x*=y;
		x/=y;
		x%=y;
		//!x<<=1;
		//!x>>=1;
		//!x>>>=1;
		//!x&=y;
		//!x^=y;
		//!x|=y;
		//casting:
		//!boolean b=(boolean)x;
		char c=(char)x;
		byte b=(byte)x;
		short s=(short)x;
		int i=(int)x;
		long l=(long)x;
		double d=(dpuble)x;
	}
	
	void doubletest(double x,double y)
	{
		//Arithmatic operators:
		x=x*y;
		x=x/y;
		x=x%y;
		x=x+y;
		x=x-y;
		x++;
		x--;
		x=+y;
		x=-y;
		//Ralational and logical:
		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);
		//bitwise operators:
		//!x=~y;
		//!x=x&y;
		//!x=x|y;
		//!x=x^y;
		//!x=x<<1;
		//!x=x>>1;
		//!x=x>>>1;
		//compound assignment:
		x+=y;
		x-=y;
		x*=y;
		x/=y;
		x%=y;
		//!x<<=1;
		//!x>>=1;
		//!x>>>=1;
		//!x&=y;
		//!x^=y;
		//x|=y;
		//casting :
		//!boolean b=(boolean)x;
		char c=(char)x;
		byte b=(byte)x;
		short s=(short)x;
		int i=(int)x;
		long l=(long)x;
		float f=(float)x;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -