JAVA 方法调用找出数组最大值
public class Homework01 { //编写一个main方法 public static void main(String[] args) { A01 p1 = new A01(); double[] arr = {1.3, 5.5, 4.2};//= null 或者 = {} Double res = p1.max(arr); if (res != null) { System.out.println("数组最大值" + res); } else { System.out.println("数组为空,请重新输入"); } } } //编写类A01,定义方法max,实现求某个double数组的最大值,并返回 //接着优化,考虑两种情况,一种是无数列值的= {},一种是数列为= null class A01 { public Double max(double arr[]) { if (arr != null && arr.length > 0) { double max = arr[0]; for (int i = 1;i < arr.length ;i++ ) { if (arr[i] > max) { max = arr[i]; } } return max; } else { return null; } } }