Computer Science, asked by atanupal196133, 5 months ago

Find the output:-
int a[4]={2,4,6,8};
for(i=0;i<=1;i++)
{
s=a[i]+a[3-i];
System.out.println(s);
}

Answers

Answered by Oreki
3

Output:

10

10

Explanation:

    Iteration 1 (when i = 0) -

        s = a[i] + a[3 - i];

        > s = 2 + 8

        > s = 10

    Iteration 2 (when i = 1) -

        s = a[i] + a[3 - i];

        > s = 4 + 6

        > s = 10

    Iteration 3 (when i = 2) -

        Condition becomes false so, loop terminates.

Similar questions