• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

for each loop and array

 
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


output as per the solution is: 0 0 3 0

when i solved i thought
first loop:
a[1]=0
a[2]=0
a[3]=0
a[4]=0 ArrayIndexOutOfBounceException

ranchers please tell me where am i wrong ?? this question is from john mayer's mock exam

avi sinha

 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See carefully the content of your array provided there. The content of array is changing within loop.

the loop will execute the following code:

a[1]=0
a[0]=0
a[3]=0
a[0]=0


 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This Example is from Inquisition.

Might this can help you..


First loop :-i=1 and arr = {1,2,3,4}
arr[1] = 0; and arr becomes {1,0,3,4}
--------------------------------------------
sec loop :-i=0 and arr = {1,0,3,4}
arr[0] = 0; and arr becomes {0,0,3,4}
--------------------------------------------
Third loop :-i=3 and arr = {0,0,3,4}
arr[3] = 0; and arr becomes {0,0,3,0}
--------------------------------------------
Fourth loop :-i=0 and arr = {0,0,3,0}
arr[0] = 0; and arr becomes {0,0,3,0}
--------------------------------------------
--------------------------------------------

final output - {0,0,3,0}
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks everyone my mistake ........ m such a fool
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic