# multidimensional array question..

kanaka tam

Ranch Hand

Posts: 42

posted 10 years ago

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

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

Layne Lund

Ranch Hand

Posts: 3061

posted 10 years ago

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 ]

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 ]