wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays doubt" Watch "Arrays doubt" New topic
Author

Arrays doubt

a alph
Ranch Hand

Joined: Nov 18, 2008
Posts: 36
Hi,
This question is taken from Inquisition.



Choose one option:
A) Compile error
B) Prints 0 0 0 0
C) Prints 0 1 2 3
D) Prints 0 2 0 0
E) Prints 0 0 3 0
F) Runtime exception occurs.

The answer is option E.

I thought the answer was option B. Can anyone please explain this to me.

Thanks.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18754
    
  40

a alph wrote:
The answer is option E.

I thought the answer was option B. Can anyone please explain this to me.


This question come up many times on the Ranch -- just do a search. Short answer -- even though i is used as an index, it isn't set to the indexes of the array by the loop.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
a alph
Ranch Hand

Joined: Nov 18, 2008
Posts: 36
Thanks Henry.
I did a search and found the answer.
Thanks for your reply.
 
 
subject: Arrays doubt