java 函数传递多参数案例


public class WrapperClassDemo1 {
    
    public static void main(String[] args){
        printMax(3,3,32,34.2);
        printMax(new double[]{1,2,3});
    }
    
    public static void printMax( double... numbers){
        if(numbers.length == 0){
            System.out.println("No argument passed");
            return;
        }
        
        double result = numbers[0];
        for(int i = 1;i < numbers.length;i++){
            if(numbers[i] > result){
                result = numbers[i];
            }
        }
        
        System.out.println("The max value is :" + result);
    }

}
  • The max value is :34.2
  • The max value is :3.0
posted @   盘思动  阅读(104)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示