• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

multidimensional array question..

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello folks,
Here is a question from Java How to Program by Dietel & Dietel. The question is
A m-by-n array has ____ m rows _______and ____n columns __and _________ elements.

I figured the first two blanks as m rows and n colums and the last blank is what i could n't get. Yes, this is an assignment question and i did read the whole chapter. Any help appreciated.
Thanx,
kt
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you draw out a grid with m rows and n columns, how many individual cells are in the grid? This is euqivalent to the number of elements in an m-by-n array. Note that you can't write this as a single numerical value, or even as a single variable. But you CAN calculate it with the variables given. What mathematical operation would you use?

I should note that Java does not enforce the idea of rows and columns in a 2D array. It is often easier for us to think of them that way, but you should remember that this is only a trick in thinking about how arrays work. For example, if we declare an array as:



You can think of this as an array with 10 rows and 20 columns or as an array with 20 columns and 10 rows. The first interpretation is probably the most natural since it mimics matrix notation from linear algebra (if you are familiar with that field in mathematics), but the second interpretation may be more natural, depending on how the array will be used. In either case, the number of elements is the same. (How many elements does this example array have?)

Layne
[ May 22, 2005: Message edited by: Layne Lund ]
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mn (m times n)
reply
    Bookmark Topic Watch Topic
  • New Topic