class Demo2

public class Demo2 {

    public static void main(String[] args){
        //函数重载演示2
        add(1, 3.0);
        add(1, 2);
    }
    public static double add(int a, int b){
        System.out.println("两个参数的总和: "+ (a+b));
        return 3.14;
    }    
    //重复定义
    public static int add(int a, double b){
        System.out.println("double参数的总和: "+ (a+b));
        return 12;
    }

    /*
    public static void main(String[] args){
    //函数重载演示1
        int sum=add(1, 3);
        System.out.println("两个参数的总和: "+ sum);
    }
    public static int add(int a, int b){
        return a+b;
    }
    //重定向
    public static int add(int a, double b){
        return a-(int)(b);
    }
    */
    /*
    public static void main(String[] args){
        int sum=add(1,2);
        System.out.println("两个参数的总和: "+ sum);
        sum=add(1,2,3);
        System.out.println("三个参数的总和: "+ sum);
        sum=add(1,2,3,4);
        System.out.println("四个参数的总和: "+ sum);
    } 
    //这些函数都是在做加法运算。
    public static int add(int a, int b){
        return a+b;
    }
    public static int add(int a , int b , int c){
        return a+b+c;
    }
    public static int add(int a , int b , int c,int d){
        return a+b+c+d;
    }
    */
    /*
    public static void main(String[] args){
        add(1,2);
        add(1,2,3);
        add(1,2,3,4);
    } 
    //这些函数都是在做加法运算。
    public static void add(int a, int b){
        System.out.println("两个参数的总和: "+ (a+b));
    }
    public static void add(int a , int b , int c){
        System.out.println("三个参数的总和: "+ (a+b+c));
    }
    public static void add(int a , int b , int c,int d){
        System.out.println("四个参数的总和: "+ (a+b+c+d));
    }
    */
    /*
    public static void main(String[] args){
        String result = getGrade(90);    //调用函数
        System.out.println("对应的等级是:"+ result );
    }

    public static String  getGrade(int score){    //未知的参数定义在形参中, 由函数的调用者确定。
        if(score>=90&&score<=100){
            return "A等级";
        }else if(score>=80&&score<=89){
            return "B等级";
        }else if(score>=70&&score<=79){
            return "C等级";
        }else if(score>=60&&score<=69){
            return "D等级";
        }else if(score>=0&&score<=59){
            return "E等级";
        }else{
            return "无";
        }    
    }*/
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值