Skip to content

Commit d6024f9

Browse files
authored
Make FindMin a proper utilty class (TheAlgorithms#4397)
1 parent fa77b50 commit d6024f9

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

src/main/java/com/thealgorithms/maths/FindMin.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
package com.thealgorithms.maths;
22

3-
import java.util.Arrays;
4-
import java.util.Random;
5-
6-
public class FindMin {
7-
8-
/**
9-
* Driver Code
10-
*/
11-
public static void main(String[] args) {
12-
Random random = new Random();
13-
14-
/* random size */
15-
int size = random.nextInt(100) + 1;
16-
int[] array = new int[size];
17-
18-
/* init array with random numbers */
19-
for (int i = 0; i < size; i++) {
20-
array[i] = random.nextInt() % 100;
21-
}
22-
23-
assert Arrays.stream(array).min().getAsInt() == findMin(array);
3+
public final class FindMin {
4+
private FindMin() {
245
}
256

267
/**
@@ -30,7 +11,7 @@ public static void main(String[] args) {
3011
* @exception IllegalArgumentException input array is empty
3112
* @return the mimum value stored in the input array
3213
*/
33-
public static int findMin(int[] array) {
14+
public static int findMin(final int[] array) {
3415
if (array.length == 0) {
3516
throw new IllegalArgumentException("array must be non-empty.");
3617
}

0 commit comments

Comments
 (0)