Java Array Min Value min(float[][] a)

Here you can find the source of min(float[][] a)

Description

Gets the min value of a real array.

License

Apache License

Parameter

Parameter Description
a array

Return

min

Declaration

public static float min(float[][] a) 

Method Source Code

//package com.java2s;
/*/*w ww .  j a  va 2  s .co m*/
 * Copyright 2016 Universidad Nacional de Colombia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Gets the min value of a real array.
     *
     * @param a array
     * @return min
     */
    public static float min(float[][] a) {
        checkDimension(a);
        int M = a.length;
        int N = a[0].length;
        float min = a[0][0];

        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                min = Math.min(min, a[i][j]);
            }
        }
        return min;
    }

    /**
     * Gets the min value of a real array.
     *
     * @param a array
     * @return min
     */
    public static double min(double[][] a) {
        checkDimension(a);
        int M = a.length;
        int N = a[0].length;
        double min = a[0][0];

        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                min = Math.min(min, a[i][j]);
            }
        }
        return min;
    }

    private static void checkDimension(float[][] a) {
        if (a.length == 0) {
            throw new IllegalArgumentException("Arrays dimension must be greater than 0.");
        } else if (a[0].length == 0) {
            throw new IllegalArgumentException("Arrays dimension must be greater than 0.");
        }
    }

    private static void checkDimension(double[][] a) {
        if (a.length == 0) {
            throw new IllegalArgumentException("Arrays dimension must be greater than 0.");
        } else if (a[0].length == 0) {
            throw new IllegalArgumentException("Arrays dimension must be greater than 0.");
        }
    }
}

Related

  1. min(float[] floats)
  2. min(float[] ids)
  3. min(float[] in, int[] idx)
  4. min(float[] numbers)
  5. min(float[] v1, float[] v2)
  6. min(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
  7. min(int receiver, int... others)
  8. min(int value1, int value2, int... values)
  9. min(int... _is)