Consider the static method cube() below.
How many times is the following for loop iterated?
Answer: Just 1,000 times. A call to cube() has no effect on the client code. It changes the value of its local parameter variable i, but that change has no effect on the i in the for loop, which is a different variable. If you replace the call to cube(i) with the statement i = i * i * i; (maybe that was what you were thinking), then the loop is iterated five times, with i taking on the values 0, 1, 2, 9, and 730 at the beginning of the five iterations.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here