Here you can find the source of maxMinValues(long[] array)
Parameter | Description |
---|---|
array | Input array |
public static long[] maxMinValues(long[] array)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Pablo Pavon-Marino. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors:/*from ww w. j a v a2 s.com*/ * Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1 * Pablo Pavon-Marino - from version 0.4.0 onwards ******************************************************************************/ import java.util.*; public class Main { /** * Returns the maximum/minimum values of an input array. * * @param array Input array * @return Maximum/minimum values * */ public static long[] maxMinValues(long[] array) { if (array.length == 0) { throw new NoSuchElementException("Empty array"); } long maxValue = array[0]; long minValue = array[0]; for (int i = 1; i < array.length; i++) { if (array[i] > maxValue) { maxValue = array[i]; } if (array[i] < minValue) { minValue = array[i]; } } return arrayOf(maxValue, minValue); } /** * Generates a {@code long[]} from comma-separated values. * * @param values Comma-separated {@code long} values * @return {@code long[]} * */ public static long[] arrayOf(long... values) { return values; } }