public class Q6 { public static void main(String[] args) { int a[]={4,5,9,8,6,6,0}; int i=1; a[i]=i+=a[i++]; System.out.println(a[i]+" , "+i); } } please explain the way output is coming? 0,6

i starts at 1 so a[1] gives you 5 (the second element of the array is 5) i+=5 gives you 6 a[6] gives you 0 (the 7th element of the array is 0). So the value of i ends up 6, and the valus of a[i] is 0.

"JavaRanch, where the deer and the Certified play" - David O'Meara

hi, i got it this way. Hope it's correct. a[i]=i+=a[i++]; initially i = 1 so, expression become, a[1] = i+ = a[1] Now, Evaluating from Right to left first i+=a[1]; i = i + a[1] = 6 then a[1] = 6 Therefore a[6] remains 0 and i is now 6