• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Array

 
Lata Bagga
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Lata Bagga
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Vishwanath for such a nice explanation. I got it now.
 
Akshay Dashrath
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did'nt understand this . What happens to arr[2] and why does arr[0] come twice?

Thanks,
Akshay
 
ishmayel vemuru
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishwa..
Thanks for your Reply..
Regards..
Ishmayel.
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is very nice question
thanks to Vishwa for fantastic explanation
 
Raphael Rabadan
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice question :-)
 
Milan Sutaria
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic