package day16; public class Method_Demo01 { public static void main(String[] args) { //定义一些数据用于比较﹑计算两个值是否相等 byte a = 10; byte b = 20; short c = 10; short d = 20; int e = 10; int f = 10; long g = 20; long h = 20; Count c1 = new Count(); System.out.println(c1.compare(a, b)); System.out.println(c1.compare(c, d)); System.out.println(c1.compare(e, f)); System.out.println(c1.compare(g, h)); } } class Count { //方法重载同一个类中可以有相同的方法但里面的参数不同 // 1 usage public boolean compare(byte x1,byte y1){ // x1 = a = 10,y1 = b = 20; // return false return x1 == y1; } public boolean compare(short x2, short y2){ // x2 = c = 10,y2 = d = 20; // return false return x2 == y2; } //1 usage public boolean compare(int x3, int y3){ //x3 = e = 10, y3 = f = 10; //return truel return x3 == y3; } //1 usage public boolean compare(long x4,long y4){ // x4 = g = 20,y4 = h = 20 ; // return true return x4 == y4; } }
比较﹑计算两个值是否相等
最新推荐文章于 2022-11-15 18:40:23 发布