User Story
As a developer, I want to write a code that finds the maximum integer from a given list of integers
Codes
public class MaxIntegerFinder {
public static Integer findMaxInteger(List<Integer> integerList) {
if (integerList == null || integerList.isEmpty()) {
throw new IllegalArgumentException('The list cannot be null or empty');
}
Integer maxInteger = integerList.get(0);
for (Integer i = 1; i < integerList.size(); i++) {
if (integerList.get(i) > maxInteger) {
maxInteger = integerList.get(i);
}
}
return maxInteger;
}
}
Test Class
@isTest
public class MaxIntegerFinderTest {
@isTest
static void testFindMaxInteger() {
List<Integer> intList = new List<Integer>{5, 4, 3, 2, 8};
Integer maxInteger = MaxIntegerFinder.findMaxInteger(intList);
System.assertEquals(8, maxInteger);
}
}
Video
Video does not exists.