This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "multidimensional array question.." Watch "multidimensional array question.." New topic
Author

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.
Thanx,
kt
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?)

Layne
[ 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: http://aspose.com/file-tools
 
subject: multidimensional array question..
 
Similar Threads
Sorting Issue Help Needed Badly
neep help
Reference Book
?(book) from a newbie
answers