File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays doubt

 
a alph
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
a alph
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic