public class ArrayLengthNotZeroException extends RuntimeException {
public ArrayLengthNotZeroException() {
super("Array length must not be zero.");
}
}
public class ArrayUtil {
public static int findMax(int[] array) {
if (== 0) {
throw new ArrayLengthNotZeroException();
}
int max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
}
public class Main {
public static void main(String[] args) {
int[] array = {};
try {
int max = ArrayUtil.findMax(array);
System.out.println("Max value: " + max);
} catch (ArrayLengthNotZeroException e) {
System.out.println("Error: " + e.getMessage());
}
}
}