From d6024f9cd49e3dc33576cb949ba379e62ad42528 Mon Sep 17 00:00:00 2001 From: Piotr Idzik <65706193+vil02@users.noreply.github.com> Date: Sun, 24 Sep 2023 12:25:28 +0200 Subject: [PATCH] Make `FindMin` a proper utilty class (#4397) --- .../java/com/thealgorithms/maths/FindMin.java | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/thealgorithms/maths/FindMin.java b/src/main/java/com/thealgorithms/maths/FindMin.java index cab03628a..10a03c801 100644 --- a/src/main/java/com/thealgorithms/maths/FindMin.java +++ b/src/main/java/com/thealgorithms/maths/FindMin.java @@ -1,26 +1,7 @@ package com.thealgorithms.maths; -import java.util.Arrays; -import java.util.Random; - -public class FindMin { - - /** - * Driver Code - */ - public static void main(String[] args) { - Random random = new Random(); - - /* random size */ - int size = random.nextInt(100) + 1; - int[] array = new int[size]; - - /* init array with random numbers */ - for (int i = 0; i < size; i++) { - array[i] = random.nextInt() % 100; - } - - assert Arrays.stream(array).min().getAsInt() == findMin(array); +public final class FindMin { + private FindMin() { } /** @@ -30,7 +11,7 @@ public class FindMin { * @exception IllegalArgumentException input array is empty * @return the mimum value stored in the input array */ - public static int findMin(int[] array) { + public static int findMin(final int[] array) { if (array.length == 0) { throw new IllegalArgumentException("array must be non-empty."); }