- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathFindMax.java
27 lines (25 loc) · 713 Bytes
/
FindMax.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
packagecom.thealgorithms.maths;
publicfinalclassFindMax {
privateFindMax() {
}
/**
* @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
*/
publicstaticintfindMax(finalint[] array) {
intn = array.length;
if (n == 0) {
thrownewIllegalArgumentException("Array must be non-empty.");
}
intmax = array[0];
for (inti = 1; i < n; i++) {
if (array[i] > max) {
max = array[i];
}
}
returnmax;
}
}