重载复习和小练习
有兴趣的可以看看注释里面的题目要求,自己写写或者看看下面的用别的方式完成目标。
/*
题目要求:
比较两个数据是否相等,
参数类型分别是byte,short,int,long
然后在main方法中测试
*/
public class HelloWorld {
public static void main(String[] args) {
byte x = 10;
byte y = 20;
System.out.println(sum(x, y));
System.out.println(sum((short) 20, (short) 20));
System.out.println(sum(20, 10));
System.out.println(sum(20L,10L));
}
public static boolean sum(byte x, byte y) {
if (x == y) {
return true;
} else {
return false;
}
}
public static boolean sum(short x, short y) {
boolean sum = x == y ? true : false;
return sum;
}
public static boolean sum(int x, int y) {
return x == y;
}
public static boolean sum(long x, long y) {
boolean max;
if (x == y) {
max = true;
} else {
max = false;
}
return max;
}
}
/*
题目要求:
比较两个数据是否相等,
参数类型分别是byte,short,int,long
然后在main方法中测试
*/
public class HelloWorld {
public static void main(String[] args) {
byte x = 10;
byte y = 20;
System.out.println(sum(x, y));
System.out.println(sum((short) 20, (short) 20));
System.out.println(sum(20, 10));
System.out.println(sum(20L,10L));
}
public static boolean sum(byte x, byte y) {
if (x == y) {
return true;
} else {
return false;
}
}
public static boolean sum(short x, short y) {
boolean sum = x == y ? true : false;
return sum;
}
public static boolean sum(int x, int y) {
return x == y;
}
public static boolean sum(long x, long y) {
boolean max;
if (x == y) {
max = true;
} else {
max = false;
}
return max;
}
}
人生苦短。希望大家能和我交流学习哦。
右侧分类下的每篇文章都有排序方便阅读。