Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Hard

Question 40

Given code:

Which 3 options, if used to replace /*INSERT*/, on execution will print 9 on to the console?

  • A

    int n = 3; n < arr.length; n++ 

  • B

    int n = 1; n < arr.length - 1; n++ 

  • C

    int n = 1; n < arr.length; n += 2 

  • D

    int n = 0; n < arr.length; n++ 

  • E

    int n = 0; n < arr.length; n += 2 

Reveal correct answers

Correct answers: A, B, E

Explanation

Logic in for loop is adding array elements. You need to find out which array elements when added will result in 9. Possible options are: {1+3+5, 2+3+4, 4+5}.

Based on these 3 combinations you can select 3 correct options.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need