Author |
Message |
SsJBebiGoku
|
Posted: Thu Oct 07, 2004 6:44 pm Post subject: Mutlidimensional Array question |
|
|
Hi,
I'm writing a program to generate a random number of hands and everything...(another file calls the stuff and outputs it later), but i dont know how to get the length of a multidimensional array..i know for a regular array you use Array.getLength(x), but does anybody know how to do it for a multidimensional one? i'll put the piece of code that i'm trying to get it from..thanks a bunch
code: |
public void dealCards(int hand[][], int numCards)
{
int firstArray = Array.getLength(?);
int secondArray = Array.getLength(?);
System.out.println(firstArray + " " + secondArray);
for (int j = 0; j<secondArray; j++)
{
System.out.println("Hand number " + (j+1));
for (int i = 0; i<numCards; i++)
{
etc.
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Thu Oct 07, 2004 7:37 pm Post subject: (No subject) |
|
|
why would you want a 2D array if you're dealing with cards? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
wtd
|
Posted: Thu Oct 07, 2004 7:39 pm Post subject: (No subject) |
|
|
Indeed. Each card should be an object of class Card, and a hand and deck should also be objects of class Hand and Deck, each inheriting from CardCollection. |
|
|
|
|
|
SsJBebiGoku
|
Posted: Thu Oct 07, 2004 7:51 pm Post subject: (No subject) |
|
|
i know, that's what i would do if it were up to me, but my teacher specifically laid it out adn everything..and she said to just do a single arrya for hand and just call it 4 times..so would that be easier? should i change them all back? or is there a way to get the length of both arrays? |
|
|
|
|
|
Tony
|
Posted: Thu Oct 07, 2004 8:14 pm Post subject: (No subject) |
|
|
well your teacher is an idiot hah
well you know you're calling it 4 times.. if thats the way you must do it (For whatever stange reason) than you know thats your size |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Martin
|
Posted: Fri Oct 08, 2004 12:27 am Post subject: (No subject) |
|
|
In reality, there is no such thing as a multi-dimensional array. All that a 'multi-dimensional array' is, is an array of arrays. Take the following:
int[][] x = new int[4][5];
x.length() == 4
x[3].length() == 5 |
|
|
|
|
|
rizzix
|
Posted: Fri Oct 08, 2004 11:12 am Post subject: (No subject) |
|
|
yep but multidimensional arrays of a rectangular shape... just like Darkness's example above.. are usually a single dimensional array internally.. the [][] are just a syntax to access that array for your convenience. |
|
|
|
|
|
|