"moon" <> wrote in message
news: m...
> Hi Andrew,
> sorry i didnt mention what i was trying to do. i want to display all
> the cards in a deck..so for example, it should print out: ace of
> clubs, two of clubs, three of clubs, ace of spades, two of spades,
> etc...
-----------------
change 20 to 52 in the 'for' loop at the bottom
this does what you want
sample output
---
7 of Hearts
2 of Diamonds
9 of Diamonds
Queen of Clubs
King of Diamonds
8 of Hearts
3 of Diamonds
Queen of Diamonds
6 of Diamonds
Jack of Hearts
Jack of Diamonds
10 of Diamonds
3 of Spades
Queen of Hearts
Jack of Clubs
2 of Hearts
5 of Clubs
Queen of Spades
5 of Spades
7 of Clubs
---
-----------------
// program that prints 20 random cards
//
// Here is a solution from the master of collections himself,
// Joshua Bloch.
// Mon Oct 6 00:39:19 CDT 2003
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Deal {
public static void main(String args[]) {
// Make a standard 52-card deck
String[] suit =
new String[] { "Spades", "Hearts", "Diamonds", "Clubs" };
String[] rank =
new String[] {
" Ace",
" 2",
" 3",
" 4",
" 5",
" 6",
" 7",
" 8",
" 9",
" 10",
" Jack",
"Queen",
" King" };
List deck = new ArrayList();
for (int i = 0; i < suit.length; i++) {
for (int j = 0; j < rank.length; j++) {
deck.add(rank[j] + " of " + suit[i]);
}
}
Collections.shuffle(deck);
for (int j = 0; j < 20; j++) {
System.out.println(deck.get(j));
}
}
}
|