您的位置:首页 > 其它

C-2 方法重载,比较大小

2015-08-20 11:18 162 查看
/*
方法重载
比较两个数据是否相等,参数类型分别为
两个byte、两个short、两个int、两个long
*/

class FunctionTest{
public static void main(String[] args){

//测试
byte b1 = 3;
byte b2 = 4;
System.out.println("byte:"+compare(b1,b2));

//测试
int i1 = 11;
int i2 = 11;
System.out.println("int:"+compare(i1,i2));

//测试
short s1 = 7;
short s2 = 9;
System.out.println("short:"+compare(s1,s2));

//测试
long l1 = 7;
long l2 = 9;
System.out.println("long:"+compare(l1,l2));
}

//byte类型
public static boolean compare(byte a, byte b){
System.out.println("byte:");
return a == b;
}
//int类型
public static boolean compare(int a, int b){
System.out.println("int:");
return a == b;
}
//short类型
public static boolean compare(short a, short b){
System.out.println("short:");
return a == b;
}
//long类型
public static boolean compare(long a, long b){
System.out.println("long:");
return a == b;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: