Meaningless Drivel is fun!*
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
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: 18117
    
  39

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays doubt
 
Similar Threads
Why will I get this output?
Arrays
how to use array in array?
here is a question and i have a very similar code but i need to convert it
Three dim array