| 1 | package com.thealgorithms.maths; |
| 2 | |
| 3 | public final class AbsoluteMax { |
| 4 | private AbsoluteMax() { |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Finds the absolute maximum value among the given numbers. |
| 9 | * |
| 10 | * @param numbers The numbers to compare. |
| 11 | * @return The absolute maximum value. |
| 12 | * @throws IllegalArgumentException If the input array is empty or null. |
| 13 | */ |
| 14 | public static int getMaxValue(int... numbers) { |
| 15 | if (numbers == null || numbers.length == 0) { |
| 16 | throw new IllegalArgumentException("Numbers array cannot be empty or null"); |
| 17 | } |
| 18 | int absMax = numbers[0]; |
| 19 | for (int i = 1; i < numbers.length; i++) { |
| 20 | if (Math.abs(numbers[i]) > Math.abs(absMax) || (Math.abs(numbers[i]) == Math.abs(absMax) && numbers[i] > absMax)) { |
| 21 | absMax = numbers[i]; |
| 22 | } |
| 23 | } |
| 24 | return absMax; |
| 25 | } |
| 26 | } |
nothing calls this directly
no outgoing calls
no test coverage detected