靜態類求最大值最小值

mpsky發表於2021-09-09
package example;

public class MaxMin {
    public static class Result {
        private double max;
        private double min;
        public Result(double max,double min) {
            this.max=max;
            this.min=min;
        }
        public double getMax() {
            return max;
        }
        public double getMin() {
            return min;
        }
    }
    public static Result getResult(double array[]) {
        double max=Double.MIN_VALUE;
        double min=Double.MAX_VALUE;
        for (double i : array) {
            if(i>max) {
                max=i;
            }
            else
                min=i;
        }
        return new Result(max,min);
    }
    public static void main(String[] args) {
        double array[]=new double[5];
        for (int i = 0; i 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1806/viewspace-2798007/,如需轉載,請註明出處,否則將追究法律責任。

相關文章