mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-26 05:59:22 +08:00

* Fixed Small typos :-) * Update BufferedReader.java * Made the following changes : * Improved readability of files and removed gramatical errors. * Implemented data assigning instead of manually calling arr.ylength in several instances like FindMax, FindMaxRecursion etc. * Removed unwanted params from several files * Implemented Math methods in files math/FindMinRecursion.java and FindMaxRecursion.java * Update src/main/java/com/thealgorithms/maths/FindMinRecursion.java --------- Co-authored-by: Debasish Biswas <debasishbsws.dev@gmail.com>
28 lines
713 B
Java
28 lines
713 B
Java
package com.thealgorithms.maths;
|
|
|
|
public final class FindMax {
|
|
private FindMax() {
|
|
}
|
|
|
|
/**
|
|
* @brief finds the maximum value stored in the input array
|
|
*
|
|
* @param array the input array
|
|
* @exception IllegalArgumentException input array is empty
|
|
* @return the maximum value stored in the input array
|
|
*/
|
|
public static int findMax(final int[] array) {
|
|
int n = array.length;
|
|
if (n == 0) {
|
|
throw new IllegalArgumentException("Array must be non-empty.");
|
|
}
|
|
int max = array[0];
|
|
for (int i = 1; i < n; i++) {
|
|
if (array[i] > max) {
|
|
max = array[i];
|
|
}
|
|
}
|
|
return max;
|
|
}
|
|
}
|