继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

静态类求最大值最小值

长是人千离
关注TA
已关注
手记 5
粉丝 5
获赞 21
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 < array.length; i++) {
            array[i]=100*Math.random();
        }
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
        System.out.println(MaxMin.getResult(array).getMax());
    }
}
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP