What is the output of the following code snippet: for(int i = 0; i < 5; i++) { System.out.print(i + " "); }?

  • 0 1 2 3 4
  • 0 1 2 3 4 5
  • 1 2 3 4
  • 1 2 3 4 5
The correct output is "0 1 2 3 4." This is because the loop initializes i to 0, iterates as long as i is less than 5, and increments i by 1 in each iteration. It prints the value of i followed by a space in each iteration. When i reaches 5, the loop terminates.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *