Venciity

[SoftUni Java] ExamPreparation 04.PokerStraight

May 24th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class _04_PokerStraight {
  5.  
  6.     public static void main(String[] args) {
  7.         @SuppressWarnings("resource")
  8.         Scanner input = new Scanner(System.in);
  9.         int targetWeight = input.nextInt();
  10.         String[] cardFaces = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
  11.         String[] cardSuits = { "Clubs", "Diamonds", "Hearts", "Spades" };
  12.         int count = 0;
  13.         for (int face = 0; face < cardFaces.length - 4; face++)
  14.         {
  15.             for (int suit1 = 0; suit1 < cardSuits.length; suit1++)
  16.             {
  17.                 for (int suit2 = 0; suit2 < cardSuits.length; suit2++)
  18.                 {
  19.                     for (int suit3 = 0; suit3 < cardSuits.length; suit3++)
  20.                     {
  21.                         for (int suit4 = 0; suit4 < cardSuits.length; suit4++)
  22.                         {
  23.                             for (int suit5 = 0; suit5 < cardSuits.length; suit5++)
  24.                             {
  25.                                      int weight =
  26.                                     (face + 1) * 10 + suit1 + 1 +
  27.                                     (face + 2) * 20 + suit2 + 1 +
  28.                                     (face + 3) * 30 + suit3 + 1 +
  29.                                     (face + 4) * 40 + suit4 + 1 +
  30.                                     (face + 5) * 50 + suit5 + 1;
  31.                                 if (weight == targetWeight)
  32.                                 {
  33.                                     count++;
  34.  
  35.                                      //Print the straight hand + its weight
  36.                                      String card1 = cardFaces[face + 0] + cardSuits[suit1];
  37.                                      String card2 = cardFaces[face + 1] + cardSuits[suit2];
  38.                                      String card3 = cardFaces[face + 2] + cardSuits[suit3];
  39.                                      String card4 = cardFaces[face + 3] + cardSuits[suit4];
  40.                                      String card5 = cardFaces[face + 4] + cardSuits[suit5];
  41.                                      System.out.printf("(%s %s %s %s %s)",
  42.                                              card1, card2, card3, card4, card5);
  43.                                      System.out.println();
  44.                                 }
  45.                             }
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.         System.out.println(count);
  52.  
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment