Advertisement
dimipan80

Full House (better solution)

Sep 7th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. /* In most Poker games, the "full house" hand is defined as three cards of the same face
  2.  * + two cards of the same face, other than the first, regardless of the card's suits.
  3.  * The cards faces are "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" and "A".
  4.  * The card suits are "♣", "♦", "♥" and "♠".
  5.  * Write a program to generate and print all full houses and print their number. */
  6.  
  7. public class _03_FullHouse {
  8.  
  9.     private static String[] faceCards = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
  10.  
  11.     private static char[] suitCards = { '\u2663', '\u2666', '\u2665', '\u2660' };
  12.  
  13.     public static void main(String[] args) {
  14.         // TODO Auto-generated method stub
  15.         int countFullHouses = generateAndPrintAllFullHouses();
  16.  
  17.         System.out.println();
  18.         System.out.printf("The all combinations of generated full houses are: %d full houses!%n",
  19.                         countFullHouses);
  20.     }
  21.  
  22.     private static int generateAndPrintAllFullHouses() {
  23.         int counter = 0;
  24.         System.out.println("The all combinations of generated full houses with Jokers are:");
  25.         int f1, f2;
  26.         int[] colors;
  27.         for (f1 = 0; f1 < faceCards.length; f1++) {
  28.             for (f2 = 0; f2 < faceCards.length; f2++) {
  29.                 if (f2 != f1) {
  30.                     colors = new int[5];
  31.                     for (colors[0] = 0; colors[0] < suitCards.length; colors[0]++) {
  32.                         for (colors[1] = colors[0] + 1; colors[1] < suitCards.length; colors[1]++) {
  33.                             for (colors[2] = colors[1] + 1; colors[2] < suitCards.length; colors[2]++) {
  34.                                 for (colors[3] = 0; colors[3] < suitCards.length; colors[3]++) {
  35.                                     for (colors[4] = colors[3] + 1; colors[4] < suitCards.length; colors[4]++) {
  36.                                         counter++;
  37.                                         printTheNextFullHouse(f1, f2, colors);
  38.                                     }
  39.                                 }
  40.                             }
  41.                         }
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.  
  47.         return counter;
  48.     }
  49.  
  50.     private static void printTheNextFullHouse(int face1, int face2, int[] colors) {
  51.         System.out.printf("(%1$s%2$s %1$s%3$s %1$s%4$s ", faceCards[face1],
  52.                 suitCards[colors[0]], suitCards[colors[1]],
  53.                 suitCards[colors[2]]);
  54.         System.out.printf("%1$s%2$s %1$s%3$s) ", faceCards[face2],
  55.                 suitCards[colors[3]], suitCards[colors[4]]);
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement