• Post Reply Bookmark Topic Watch Topic
  • New Topic

array problems  RSS feed

 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could someone possibly explain what is happening in this code clip? It is from my java course book and i am having trouble with arrays at the moment.
The explanation in the book is kinda wierd and hard to understand...


thanks for your help
Mike
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loop 1 calculates 0..9 to the power to 2
Loop 2 prints them
Loop 3 is a tricky one. It uses the values of nummern as an array index. However because the values where never set the default value will be used which is 0; Thus it sets element 0 of nummern 10 times to 1
Loop 4 takes the values of nummern and set's it to 1. However because of you get a copy of the value of the array, the array itself is not altered it any way.
Loop 5 prints the values of the array.
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer Wouter!!

although i am still pretty confused lol, i think i will have a difficult time with arrays.I will have to keep reading and testing untill it "klicks" in my head i think.


Mike
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!