码迷,mamicode.com
首页 > 其他好文 > 详细

可变参数

时间:2021-05-24 07:25:57      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:The   int   可变参数   max value   load   val   代码   public   str   

可变参数

技术图片

package com.luo.method;

public class Demo4 {
    public static void main(String[] args) {
        Demo4 demo4 = new Demo4();
        demo4.test(1, 2, 3, 4, 5);


    }

    public void test(int... i) {
        System.out.println(i[0]);
        System.out.println(i[1]);
        System.out.println(i[2]);
        System.out.println(i[3]);
        System.out.println(i[4]);
    }
}
package com.luo.method;

public class Demo41 {
    public static void main(String[] args) {
        //调用可变参数
        printMax(34,3,3,2,56.5);
        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   int   可变参数   max value   load   val   代码   public   str   

原文地址:https://www.cnblogs.com/nanxiong/p/14763067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!