πŸ“Š JAVA
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);
  • (A) 15
  • (B) 10
  • (C) 6
  • (D) 3
πŸ’¬ Discuss
βœ… 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.

Explanation by: Deepak Sahoo
The for loop iterates over each element of the array and adds its value to the variable sum, which is then printed.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
249
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Deepak Sahoo
Publisher
πŸ“ˆ
91%
Success Rate