D

Deepak Sahoo • 10.78K Points
Tutor II

Q. What is the output of the following code?

Code:
int[] arr = new int[]{1, 2, 3, 4, 5};
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
  • (A) 1 2 3 4 5
  • (B) 5 4 3 2 1
  • (C) 1 3 5
  • (D) 2 4
  • Correct Answer - Option(A)
  • Views: 229
  • Filed under category JAVA

Explanation by: Deepak Sahoo
The for loop iterates over each element of the array and prints its value.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics