Give the output of the following:-
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
30
Answer:
output for this code segment is
10
10
the loop will run two time since i<=1 for first time i=0(which is less than 1) and second time when i=1 (as it is equal to 1)
in the first iteration
s=a[0]=a[3-0]
=a[0]+a[3] (and we know that indexing in array starts from 0)
= 2+8 = 10 so 10 is printed in first iteration
In the second Iteration
s=a[1]=a[3-1]
=a[1]+a[2]
=4+6 = 10 so 10 is printed in Second iteration
I hope this helped you so plz rate the answer....
tanisha0910:
very well explained thnq so much..
Answered by
5
Answer:
10
10
Explanation
i Output Remark
0 a[0] + a[3]
⇒ 2 + 8
⇒10 First Iteration
1 a[1] + a[2]
⇒ 4 + 6
⇒10 Second Iteration
Similar questions