public class Demo02 {
public static void main(String[] args) {
//调用可变参数的方法
printMax(2,58,44,123,548,3338.221);
printMax(new double[]{1,2.5,2.4});
}
//寻找最大值
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(result);
}
}
java寻找最大值和调用可变参数
最新推荐文章于 2024-08-30 18:40:43 发布