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

Explanation: This for loop iterates through the elements of the nums array, using the index variable i, but only printing out the elements with even indexes. The System.out.print statement prints each element followed by a space, resulting in the output “1 3 5”.

Explanation by: Pushkar
This for loop iterates through the elements of the nums array, using the index variable i, but only printing out the elements with even indexes. The System.out.print statement prints each element followed by a space, resulting in the output “1 3 5”.

πŸ’¬ Discussion


πŸ“Š Question Analytics

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