I have this code in Java, and I'm trying to figure out how it works, it stacks up until the |a[i] % 4 == 0| returns false. then it stops recursion and starts to go back up to i=0. and then prints false. Which is correct since 13 doesn't divide by 4. but I can't figure out how it works, and what it does in Java.
If someone can clarify that, I would be most grateful!
public class whatRec {
public static boolean what(int[] a) {
return what(a, 0);
}
private static boolean what(int[] a, int i) {
if (i == a.length - 1)
return a[i] % 4 == 0;
return (a[i] % 4 == 0) && what(a, i + 1);
}
public static void main(String[] args) {
int[] a = {4, 24, 13, 12, 4, 12};
System.out.println(what(a));
}