SCJP
Milind B. Patil - SCJP-1.4, SCWCD-5.0, SCBCD-5.0
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
The coirrect answer is 0030.
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Originally posted by Christian Polychroniadis:
Hi, Nabila Mohammad
Please change the array initialization, to {1,2,3,4} instead of {1,2,3,4,5}
if you included 5, you will get that error.
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Cheers, Meena
OCPJP 6
you are doing it wrong
I just went through link given by Milind and there the question is same but the value in arr in {1,2,3,4}. If I solve it on paper it gives me the answer 0030 which is the correct answer. But if I try to code it and solve it on my laptop, it gives the answer 0000. Where am I going wrong? Or the JVM is wrong?? Please help.
1.First iteration i = a[0], so i becomes 0 and we print a[i] i.e, a[0] = 0
2.First iteration i = a[1], so i becomes 0 and we print a[i] i.e, a[0] = 0
3.First iteration i = a[2], so i becomes 3 and we print a[i] i.e, a[3] = 0
4.First iteration i = a[3], so i becomes 0 and we print a[i] i.e, a[0] = 0
SCJP