重载 两个数比较相同(练习题)

题:比较两个数据是否相同。

参数类型分别为两个byte类型,两个short类型,两个int类型,两个long类型,

并且在mian方法里中进行测试。

 

public static void main(String[] args){

byte a =10;

byte  b= 20;

sout.................(isSame(a,b));

--------------

sout.................(isSame((short)10,(short)20));

--------------

sout.................(isSame(a:10,b:20));

 

--------------

sout.................(isSame(a:10L,b:20L));

 

 

 

 

}

//方法 1

public static boolean isSame(byte a,byte b){

    if(a==b){

     same = true     

    }else{

     same =false    

    }

     return same;

}

 

//方法  2 

public static boolean isSame(short a,shortb){

   boolean same = a==b  ? true:false;

   return same;

}

 

//方法 3

public static boolean isSame(int a, int b){

return   a==b;

}

 

//方法 4

public static boolean isSame( long a,long b){

   if (a==b){

     return   true;

      }else{

      return  false

}

posted @ 2020-07-23 01:06  ZHU_FENG  阅读(254)  评论(0)    收藏  举报