Which of these options most closely matches the original design:

for (int i = 0; i < 10; i++) {
    System.out.println(i);
}
Explanation
The scope of the variable i, declared in the header of the cycle, is limited by this cycle.
In order to limit the scope of the variable you need to use an external block
{
  int i = 0;
  . . .
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes