Change project structure to a Maven Java project + Refactor (#2816)

This commit is contained in:
Aitor Fidalgo Sánchez
2021-11-12 07:59:36 +01:00
committed by GitHub
parent 8e533d2617
commit 9fb3364ccc
642 changed files with 26570 additions and 25488 deletions

View File

@ -0,0 +1,36 @@
package com.thealgorithms.maths;
import java.util.Arrays;
/**
* description:
*
* <p>
* absMin([0, 5, 1, 11]) = 0, absMin([3 , -10, -2]) = -2
*/
public class AbsoluteMin {
public static void main(String[] args) {
int[] testnums = {4, 0, 16};
assert absMin(testnums) == 0;
int[] numbers = {3, -10, -2};
System.out.println("absMin(" + Arrays.toString(numbers) + ") = " + absMin(numbers));
}
/**
* get the value, returns the absolute min value min
*
* @param numbers contains elements
* @return the absolute min value
*/
public static int absMin(int[] numbers) {
int absMinValue = numbers[0];
for (int i = 1, length = numbers.length; i < length; ++i) {
if (Math.abs(numbers[i]) < Math.abs(absMinValue)) {
absMinValue = numbers[i];
}
}
return absMinValue;
}
}