Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Mutlidimensional Array question
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SsJBebiGoku




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: Thu Oct 07, 2004 7:37 pm   Post subject: (No subject)

why would you want a 2D array if you're dealing with cards?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
wtd




PostPosted: 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. Smile
SsJBebiGoku




PostPosted: 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




PostPosted: Thu Oct 07, 2004 8:14 pm   Post subject: (No subject)

well your teacher is an idiot Laughing 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Martin




PostPosted: 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




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: