方法(函数),重载

方法(函数),重载

public class Demo01 {
    public static void main(String[] args) {
        int Max = max(5,6);
        System.out.println(Max);
    }
    //比大小

    public static int max(int num1,int num2){
        if(num1 == num2){
            System.out.println("相等");
            return 0;
        }
        int a = 0;
        if (num1>num2){
            a = num1;
        }else{
            a = num2;
        }
        return a;
    }
}

方法(函数),重载

public class Demo01 {
    public static void main(String[] args) {
        double Max = max(5.0,6);
        System.out.println(Max);
    }
    //比大小

    public static int max(int num1,int num2) {
        if (num1 == num2) {
            System.out.println("相等");
            return 0;
        }
        int a = 0;
        if (num1 > num2) {
            a = num1;
        } else {
            a = num2;
        }
        return a;
    }

    public static int max(double num1,double num2){   //参数(顺序,值)不同,type不同
        if (num1 == num2) {
            System.out.println("相等");
            return 0;
        }
        int a = 0;
        if (num1 > num2) {
            a = (int) num1;
        } else {
            a = (int) num2;
        }
        return a;
    }
}

方法(函数),重载

上一篇:python题目


下一篇:狄利克雷卷积重要公式及定义