mutiple deck of cards inside a array
lets say i have 8 deck of cards how to put all of that inside a array do i have to make a multidimensional array for each deck???
ilovejava
Junior Poster in Training
77 posts since Sep 2011
Reputation Points: 10
Solved Threads: 2
Depends on how you define/store a Deck.
Ideally Deck will be a class, so you can just have an array of them:
Deck[] myDecks = new Deck[8]; // create array
for (int 1 = 0; i < myDecks.length; i++) {
myDecks[i] = new Deck(...); // initialise array
}
but if your deck is just a crummy array of Cards the you will need a 2D array
Card[][] myDecks = new Card[8][52];
// .. and initialise it all
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
^ yes.
For some bizarre reason teachers use a syllabus based on very traditional programming that insist on torturing students with naked arrays before letting them use any more useful collection classes. IMHO that's a distraction because they spend more time struggling with uninitialised array elements, trying to guess a size for the array, etc rather than thinking about algorithms and code structure.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073