Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3.  
  4. /**
  5. * Created by Ekuseru on 2015/04/26.
  6. */
  7. public class HappyFamily {
  8.  
  9. public static void main(String[] args){
  10. String[] family ={"A", "B", "C","D","E","F"};
  11. String[] job = {" 1", "\'2", "\'3", "\'4"};
  12. int count = 0;
  13.  
  14. ArrayList<String> deck = new ArrayList<String>();
  15. for (int i = 0; i < family.length; i++) {
  16. for (int j = 0; j < job.length; j++) {
  17. deck.add(family[i] + job[j]);
  18. }
  19. }
  20.  
  21. //draw random 10 cards
  22. ArrayList<String> hand = new ArrayList<String>();
  23. Collections.shuffle(deck);
  24. for (int i = 0; i < 20; i++) {
  25. hand.add(deck.get(0));
  26. deck.remove(0);
  27. }
  28.  
  29. Collections.sort(hand);
  30. String[] h = hand.toArray(new String[hand.size()]);
  31. hand.toArray(h);
  32. for(int i=0; i<h.length-4;i++){
  33. String t1 = h[i];
  34. String t2 = h[i+3];
  35. t1 = t1.split("('|\\s)")[0];
  36. t2 = t2.split("('|\\s)")[0];
  37. count = t1.equals(t2)?count+1: count;
  38. }
  39.  
  40. System.out.println(count);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement