java方法 使用 二 查找最大值
作者:互联网
package method;
public class Demo04 {
public static void main(String[] args) {
Demo04 demo04 = new Demo04();
demo04.printMax(456,454,4654.4,6.454,6544.65,465.48,4564);
demo04.printMax(new double[]{1,2,35,5,8,55,66,33,1122131,});
}
public void printMax(double... num) {
if (num.length == 0) {
System.out.println("No passed");
return;
}
double res = num[0];
// 排序
for (int i = 0; i < num.length; i++) {
if (num[i] > res) {
res = num[i];
}
}
System.out.println("The Max value is:\t" + res);
}
}
运行结果
标签:java,double,res,最大值,num,public,查找,Demo04,printMax 来源: https://www.cnblogs.com/d534/p/15077946.html