首页 > 其他 > 详细

重载复习和小练习

时间:2019-12-02 00:39:38      阅读:67      评论:0      收藏:0      [点我收藏+]

有兴趣的可以看看注释里面的题目要求,自己写写或者看看下面的用别的方式完成目标。

/*
题目要求:
比较两个数据是否相等,
参数类型分别是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;
    }
}

技术分享图片

重载复习和小练习

原文:https://www.cnblogs.com/gz18221/p/11968197.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!