Q. What is the output of the following code?
Code:
int[] arr = new int[]{1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
}
System.out.println(sum);
β
Correct Answer: (A)
15
Explanation: The for loop iterates over each element of the array and adds its value to the variable sum, which is then printed.