Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 61

Given this array:

Which two code fragments, independently, print each element in this array? (Choose two.)

A.

B.

C.

D.

E.

F.

    Correct Answer:

    The correct answers are B and E. Option B uses the enhanced for loop (also called for-each loop) which iterates over each element in the array and directly prints the value of the element. Option E uses a traditional for loop that iterates from index 0 to the length of the array and prints each element by accessing the array with the index. Option A is incorrect because it tries to use the enhanced for loop with array indexing, which is not valid. Option C is incorrect because the for loop is in an incorrect format and will result in an error. Option D is incorrect because it prints the index instead of the element. Option F is incorrect because the for loop lacks an initialization part for the variable i.

Discussion
carloswork

Answer B and E.

Harch

It's A, E

kingofkotha

B, E are correct

DarGrin

B and E are correct

Sreeni_A

B and E is correct

IbrahimAlnutayfi

Answer is BC

kkaayyyy

B and E is correct.