Question 171 · 200 in bank
Select 2Given the code fragment:
And given the requirements: 1. Process all the elements of the array in the order of entry. 2. Process all the elements of the array in the reverse order of entry. 3. Process alternating elements of the array in the order of entry. Which two statements are true? (Choose two.)
Show answer
Answer: BD
Explanation
The Correct options are BD. I'm gonna explain: A -> Wrong, because enhanced for cannot read collections in reverse and alternately, it loops through each element and only in an ascending way. B -> Correct, with standard for you can go through elements of a collection in ascending, descending and alternating ways. C -> Wrong, you can loop backwards through an i-- in the third parameter of your for with the correct condition and you can also access collections alternately instead of putting "i++" in the third parameter of the standard for you, you can put the expression "i = i + 2" or any other number you want in place of 2. D -> Correct, an enhanced for processes all elements of an array in input form. E -> Wrong, you can do it alternately with a standard for as I explained in alternative C.
Source: Adapted from community discussion — iSnover


