aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Array 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 "Doubt in Array" Watch "Doubt in Array" New topic
Author

Doubt in Array

Lata Bagga
Ranch Hand

Joined: Jun 13, 2007
Posts: 35
Hello Friends,

I have a doubt in the following code:



The answer is c.

I am not able to understand how the code works and gives the output as c.

Regards,
Lata
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
Hi Lata,



for the first value in the array:
arr[1]<-- 0
so arr becomes,
{1,0,3,4}

for the next value in the array: [Remb: The array is changed now]

arr[0]<-- 0;
and arr is now,
{0,0,3,4}

for the next value in the array:

arr[3]<--0
gives
{0,0,3,0}

and for the last value in the array:
arr[0]<--0
so, arr remains {0,0,3,0}

Regards,
Vishwa


Blog
Lata Bagga
Ranch Hand

Joined: Jun 13, 2007
Posts: 35
Thanks a lot Vishwanath for such a nice explanation. I got it now.
Akshay Dashrath
Greenhorn

Joined: Jan 10, 2008
Posts: 11
I did'nt understand this . What happens to arr[2] and why does arr[0] come twice?

Thanks,
Akshay
ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi Vishwa..
Thanks for your Reply..
Regards..
Ishmayel.
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

this is very nice question
thanks to Vishwa for fantastic explanation


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Raphael Rabadan
Ranch Hand

Joined: Jul 05, 2008
Posts: 141
Nice question :-)


SCJP Java 6 (98%) - Story, SCJA (88%) - Story
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 121
its a nice Question Lata and a nice explaination by murthi too.

For those who did not get it .... try reading Arrays
[ July 15, 2008: Message edited by: Milan Sutaria ]

SCJP 6 83%
Working on SCWCD/OCPJWCD
 
 
subject: Doubt in Array