Hello,
in the following example program in Java, I get infinite loop, and I cannot understand why:
public class Time {
public static int next(int v) {
return v++;
}
public static void main(String[] args) {
int[] z = {3, 2, 1, 0};
int i = 1;
while(i < 4) {
System.out.println(z[i]/z[i]);
i = next(i);
}
}
}
In the while-loop the method next() is invoked, and i should be incremented every time by 1: next() should return i++, and the value of i in the while loop should be incremented by one.
Why could be the reason for the infinite loop? Thank you.