zh_stoqnov

RandomCards

Jan 24th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.Scanner;
  4.  
  5. public class RandomHandsOfFiveCards {
  6. public static void main(String[] args) {
  7. Scanner input = new Scanner(System.in);
  8.  
  9. int n = input.nextInt();
  10. generateFiveRandomCards(n);
  11. }
  12.  
  13. public static void generateFiveRandomCards(int n) {
  14. ArrayList<String> cards = new ArrayList<String>();
  15.  
  16. String[] faces = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
  17. char[] suits = { '\u2663', '\u2666', '\u2665', '\u2660' };
  18.  
  19. for(int i = 0; i < faces.length; i++) {
  20. for(int j = 0; j < suits.length; j++) {
  21. cards.add(faces[i] + suits[j]);
  22. }
  23. }
  24.  
  25. for(int i = 0;i < n; i++){
  26. Collections.shuffle(cards);
  27. ArrayList<String> fiveCards = new ArrayList<>(cards.subList(0, 5));
  28. System.out.println(fiveCards.toString().replace('[', ' ').replace(']', ' ').replaceAll(",", "").trim());
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment