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

二维数组中的最小值

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

466
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
二维数组中的最小值
/** n o w j a v a . c o m - 时  代  Java 提 供 **/

//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(minimum(arr));

    }


    public static double minimum(double[] arr) {

        double minVal = Double.POSITIVE_INFINITY;

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

            if (arr[i] < minVal) {

                minVal = arr[i];

            }/**来 自 n o w    j a v a  . c o m**/

        }

        return minVal;

    }


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

        double minVal = Double.POSITIVE_INFINITY;

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

            if (arr[i] != null) {

                minVal = Math.min(minVal, minimum(arr[i]));

            }

        }

        return minVal;

    }


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

        double minVal = 
展开阅读全文