- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathFindMin.java
26 lines (24 loc) · 703 Bytes
/
FindMin.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
packagecom.thealgorithms.maths;
publicfinalclassFindMin {
privateFindMin() {
}
/**
* @brief finds the minimum value stored in the input array
*
* @param array the input array
* @exception IllegalArgumentException input array is empty
* @return the mimum value stored in the input array
*/
publicstaticintfindMin(finalint[] array) {
if (array.length == 0) {
thrownewIllegalArgumentException("Array must be non-empty.");
}
intmin = array[0];
for (inti = 1; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
returnmin;
}
}