for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
System.out.println("x");
}
}What is wrong?
- A
Compile-time inference fails
- B
Nothing is wrong
- C
Both loops share i and run nine times correctly
- Dcheck_circle
Inner loop redeclares i; that variable is already in the enclosing scope
Explanation
Java disallows declaring a variable with the same name as one already in an enclosing block. Rename the inner variable, e.g., j.