• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

multi-dimensional array

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
How does three-dimensional array work?
Thanks.
Luk
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kind of a generic question, but I'll try to explain as best I can (and let me know how I do, because something I'm doing for work right now is preparing to teach an intro-level Java class--as little as I know, I happen to be the "expert" in our department )
Suppose the easiest way to start is with 2-dimensional arrays, which are easy to get a handle on--it's just an array of arrays.
So for instance, suppose I was keeping an array of the mileage at which I got the oil changed in my vehicles.
So suppose:
int miles[][] = new int[2][];
miles[0] = {3000, 6000, 9000, 12000, 15000};
miles[1] = {3000, 8000, 14000, 20000};
Pretty simple concept. Now, take it to 3 dimensions--we'll keep track of the mileage of everyone in the neighborhood
so now we would have miles[][][]
miles[0] = {{3000, 6000, 9000, 12000, 15000}, {3000, 8000, 14000, 20000}}; //me
miles[1] = {{3000, 6000, 10000}, {5000, 10000, 15000, 20000}, {3000, 7000}}; //my neighbor, who has 3 cars
and so on...
Hope that helps a little, or at least raises some further questions that'll help clarify thing.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good example
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic