Hi,
Please help me to understand the output for the following question.
class JMM125 {
static int i;
public static void main(
String args[]) {
for (i=1; i<3; i++) {System.out.print(i);} // 1
for (int i=1; i<3; i++) {System.out.print(i);} // 2
int i; // 3
for (i=0; i<2; i++) {System.out.print(i);} // 4
System.out.print(JMM125.i);
}}
What is the result of attempting to compile and run the program?
a. Prints: 1212010
b. Prints: 1212013
c. Compile-time error at line 1
d. Compile-time error at line 2
e. Compile-time error at line 4
f. Run-time error
g. None of the above
what i understand from the above question is that "int i" is different each time. It is declared each time in the FOR LOOP. So the answer should be NONE OF THE ABOVE.
But the correct answer is 1212013 (option b).