我目前正在准备考试,并且正在执行以下任务:
生成包含整数的无限流
(0, 1, -1, 2, -2, 3, -3, ...)。
跟随流生成普通的无限流:
Stream<Integer> infiniteStream = Stream.iterate(1, i -> i + 1);
Run Code Online (Sandbox Code Playgroud)
是否存在同时生成正数和负数的方法或lambda表达式?
我目前正在准备考试并正在处理以下任务:
我想捕获“ArrayIndexOutOfBoundsException”。
我有以下课程:
class Util {
// get the smallest number of the given array
@SuppressWarnings("unused")
public static int minimum(int[] values) {
try {
int min = values[0];
if (values == null) {
throw new NullPointerException();
}
if (values.length > 0) {
for (int i = 1; i < values.length; i++) {
if (values[i] < min) {
min = values[i];
}
}
return min;
} else {
throw new ArrayIsEmptyException();
}
} catch (NullPointerException e) {
System.out.println("Das ist kein Array"); …Run Code Online (Sandbox Code Playgroud)