方法重載練習(xí)之比較數(shù)據(jù)是否相等
package com.itheima_03;
/*
* 比較兩個數(shù)據(jù)是否相等痴晦。
* 參數(shù)類型分別為兩個byte類型琳彩,
* 兩個short類型部凑,兩個int類型术辐,
* 兩個long類型,并在main方法中進行測試
*/
public class MethodTest {
public static void main(String[] args) {
// System.out.println(compare(10, 20));
// System.out.println(compare((byte) 10, (byte) 20));
// System.out.println(compare((short) 10, (short) 20));
System.out.println(compare(10L, 20L));
}
// byte
public static boolean compare(byte a, byte b) {
System.out.println("byte");
return a == b;
}
// short
public static boolean compare(short a, short b) {
System.out.println("short");
return a == b;
}
// int
public static boolean compare(int a, int b) {
System.out.println("int");
return a == b;
}
// long
public static boolean compare(long a, long b) {
System.out.println("long");
return a == b;
}
}