die Methode filtert alle Zahlen aus dem Indexintervall [index, workArray.length[ heraus die nicht aus zwei Ziffern bestehen und ersetzt diese durch 0. Wenn ich das mal durchlaufen lasse, dann erscheint vor dem Ergebnis in eckiger Klammer [35, 345, 7, 15, 20, 5, 550, 14, 26, 8] sprich das vorgegebene Array (array3) und ich weiß nicht warum.
LG
LG
Java:
private static int[] getTwoDigitNumberArray(int[] workArray, int index) {
int [] arrCopy = workArray.clone();
if (workArray.length > index) {
if (arrCopy[index] < 10 || 99 < arrCopy[index]) {
arrCopy[index] = 0;
}
return getTwoDigitNumberArray(arrCopy, index+1);
}
return arrCopy;
}
public static void main(String[] args) {
int[] array3 = {35, 345, 7, 15, 20, 5, 550, 14, 26, 8};
System.out.println(Arrays.toString(array3));
System.out.println(Arrays.toString(getTwoDigitNumberArray(array3, 0)));
System.out.println(Arrays.toString(getTwoDigitNumberArray(array3, 9)));
System.out.println(Arrays.toString(getTwoDigitNumberArray(array3, 8)));
System.out.println(Arrays.toString(getTwoDigitNumberArray(array3, 4)));
System.out.println();
assert (Arrays.equals(getTwoDigitNumberArray(array3, 0), new int[]{35, 0, 0, 15, 20, 0, 0, 14, 26, 0}) == true);
assert (Arrays.equals(getTwoDigitNumberArray(array3, 9), new int[]{35, 345, 7, 15, 20, 5, 550, 14, 26, 0}) == true);
assert (Arrays.equals(getTwoDigitNumberArray(array3, 8), new int[]{35, 345, 7, 15, 20, 5, 550, 14, 26, 0}) == true);
assert (Arrays.equals(getTwoDigitNumberArray(array3, 4), new int[]{35, 345, 7, 15, 20, 0, 0, 14, 26, 0}) == true);
}