public class ChangeArgsExer01 {
public static void main(String[] args) {
Count04 c=new Count04();
int maxNum=c.max(5,3,9,7);
System.out.println("最大值:"+maxNum);
}
}
class Count04{
public int max(int num,int...other){//可变参数写在所有参数后面
//默认第一个数字最大
int max=num;
for (int i=0;i<other.length;i++){
if (max<other[i]){
max=other[i];
}
}
return max;
}
}
可变参数:找最大值
最新推荐文章于 2023-02-06 23:42:12 发布