πŸ“Š JAVA
Q. What is the output of the following code?
Code:
int[] nums = {1, 2, 3, 4, 5};
for (int i = nums.length – 1; i >= 0; i–) {
System.out.print(nums[i] + ” “);
}
  • (A) “1 2 3 4 5”
  • (B) “5 4 3 2 1”
  • (C) “1, 2, 3, 4, 5”
  • (D) “5, 4, 3, 2, 1”
πŸ’¬ Discuss
βœ… Correct Answer: (B) “5 4 3 2 1”

Explanation: This for loop iterates through the elements of the nums array in reverse order, using the index variable i. The System.out.print statement prints each element followed by a space, resulting in the output “5 4 3 2 1”.

Explanation by: Pushkar
This for loop iterates through the elements of the nums array in reverse order, using the index variable i. The System.out.print statement prints each element followed by a space, resulting in the output “5 4 3 2 1”.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
175
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Pushkar
Publisher
πŸ“ˆ
94%
Success Rate