集册 Java实例教程 二维数组中的最大值

二维数组中的最大值

欢马劈雪     最近更新时间:2020-01-02 10:19:05

431
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
二维数组中的最大值
/**来 自 时   代    Java - nowjava.com**/


//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        double[] arr = new double[] { 34.45, 35.45, 36.67, 37.78, 37.0000,

                37.1234, 67.2344, 68.34534, 69.87700 };

        System.out.println(maximum(arr));

    }


    public static double maximum(double[] arr) {

        double maxVal = Double.NEGATIVE_INFINITY;

        for (int i = 0; i < arr.length; i++) {

            if (arr[i] > maxVal) {

                maxVal = arr[i];

            }

        }

        return maxVal;

    }
    /**
    N o w  J a v a  . c o m 提供 
    **/


    public static double maximum(double[][] arr) {

        double maxVal = Double.NEGATIVE_INFINITY;

        for (int i = 0; i < arr.length; i++) {

            if (arr[i] != null) {

                maxVal = Math.max(maxVal, maximum(arr[i]));

            }

        }

        return maxVal;

    }


    public static double maximum(double[][][] arr) {

        double maxVal = 
展开阅读全文