天天看點

java數組求最大值

public class ChangeArgs01 {
    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 (other[i]>max){
                max = other[i];
            }
        }
        return max;
    }
}