Given the code fragment:
Which option can replace xxx to enable the code to print 135?
A.
B.
C.
D.
Given the code fragment:
Which option can replace xxx to enable the code to print 135?
A.
B.
C.
D.
Option B is the correct answer: `int e = 0; e < 5; e += 2`. This loop initialization and condition cause the loop to iterate over the array with an increment of 2, selecting elements at indices 0, 2, and 4. The corresponding elements in the array `a[]` are 1, 3, and 5, which will be printed sequentially, resulting in the output '135'.
B is the correct answer
B is correct
Correct B
B is the right one
A STEP BY STEP ANSWER EXPLAINED - The correct answer is B: int e = 0; e < 5; e += 2 : WHY? - This option initializes e to 0, continues the loop while e is less than 5, and increments e by 2 each iteration. - This results in accessing array elements at indices 0, 2, and 4, which correspond to the values 1, 3, and 5. - Therefore, option B will enable the code to print 135.
Answer - B
B is correct
int a [] = {1,2,3,4,5}; for (int e=0; e<5; e+=2){ System.out.print(a[e]); }