What is the result?

Given the code fragment:


What is the result?
A. 20
B. 25
C. 29
D. Compilation fails
E. AnArrayIndexOutOfBoundsException is thrown at runtime

Download Printable PDF. VALID exam to help you PASS.

0 thoughts on “What is the result?

  1. Option A

    public class Calc {
    public static void main(String[] args) {

    int[] lst = {1, 2, 3, 4, 5, 4, 3, 2, 1};
    int sum = 0;
    for (int frnt = 0, rear = lst.length – 1;
    frnt = 5;
    frnt++, rear–) {
    sum = sum + lst[frnt] + lst[rear];
    }
    System.out.print (sum);

    }
    }

    Output:
    20

Leave a Reply

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


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