What is the result?

Given the code fragment:

What is the result?
A. 1 3 5 7
1 3
B. 1 2
1 3
C. 1 3
1 3 0 0
D. 1 3 followed by an ArrayIndexOutOfBoundsException
E. Compilation fails.

Download Printable PDF. VALID exam to help you PASS.

6 thoughts on “What is the result?

  1. Correct answer is:
    1 3
    1 3

    This is because the outer for loops will iterate over the contents of the array “arr” which consists of two “sub” arrays, so to say. Since the arr.length is 2, the outer for loop will iterate twice. In the first iteration, the value of “a” is going to be the first sub array (i.e. {1, 3, 5, 7}), and in the second iteration the value of “a” is going to be {1, 3}. Now comes the second for loop which iterates over the elements of each array. Since the for loop condition is i<arr.length, it means that "i" will start in 0 and stops at 1. Meaning that it will only print a[0] and a[1] for each of the arrays. Therefore, the result is going to be 1 3 followed by an empty line (from the println at the end of each inner for loop) then 13.

    10

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.