标签: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