I'm writting a method in Java with 3 argumens, the last one (int step) cannot be 0 or negative. At the moment I have it like this:
public static int[] createMonotoneIncreasingArray(int start, int end, int step) {
if (step <= 0) throw new IllegalArgumentException("Step cannot be lower than 1 in a monotone increasing array");
int[] resultArray = new int[(end - start) / step];
for (int i = 0; i < resultArray.length; i++) resultArray[i] = i * step + start;
return resultArray;
}
Is there any more elegant way to reject a non positive int in a method and avoid the exception?