File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes multidimensional array question.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "multidimensional array question.." Watch "multidimensional array question.." New topic

multidimensional array question..

kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
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.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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?)

[ May 22, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Fahd Shariff
Ranch Hand

Joined: Nov 22, 2002
Posts: 38
mn (m times n)

Fahd Shariff<br />"Let the code do the talking"
I agree. Here's the link:
subject: multidimensional array question..
jQuery in Action, 3rd edition