Advertisement
Guest User

Java_3.Pr6_RandomHandsOf5Cards

a guest
May 18th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Collections;
  3. import java.util.Scanner;
  4.  
  5. /* Write a program to generate n random hands of 5 different cards form a standard suit of 52 cards. */
  6.  
  7. public class Pr6_RandomHandsOf5Cards {
  8.  
  9. public static void main(String[] args) {
  10. Scanner in = new Scanner(System.in);
  11. int n = in.nextInt();
  12.  
  13. String[] face = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J",
  14. "Q", "K", "A" };
  15. String[] suit = { "♣", "♦", "♥", "♠" };
  16. String allCards = "";
  17.  
  18. for (int j = 0; j < 13; j++) {
  19. for (int k = 0; k < 4; k++) {
  20. allCards += face[j] + suit[k] + " ";
  21. }
  22. }
  23. String[] cards = allCards.split(" ");
  24.  
  25. for (int i = 0; i < n; i++) {
  26. Collections.shuffle(Arrays.asList(cards));
  27. System.out.printf("%s %s %s %s %s%n", cards[0], cards[1], cards[2],
  28. cards[3], cards[4]);
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement