Advertisement
dimipan80

Print a Deck of 52 Cards

Aug 8th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. /* Write a program that generates and prints all possible cards from a standard deck
  2.  * of 52 cards (without the jokers). The cards should be printed using the classical notation
  3.  * (like 5♠, A♥, 9♣ and K♦). The card faces should start from 2 to A.
  4.  * Print each card face in its four possible suits: clubs, diamonds, hearts and spades.
  5.  * Use 2 nested for-loops and a switch-case statement. */
  6.  
  7. import java.util.Locale;
  8.  
  9. public class _04_PrintADeckOf52PlayCards {
  10.  
  11.     public static void main(String[] args) {
  12.         // TODO Auto-generated method stub
  13.         Locale.setDefault(Locale.ROOT);
  14.         char clubs = '\u2663';
  15.         char diamonds = '\u2666';
  16.         char hearts = '\u2665';
  17.         char spades = '\u2660';
  18.  
  19.         for (int face = 2; face < 15; face++) {
  20.  
  21.             for (int suit = 0; suit < 4; suit++) {
  22.                 switch (face) {
  23.                 case 11:
  24.                     System.out.print("  J");
  25.                     break;
  26.                 case 12:
  27.                     System.out.print("  Q");
  28.                     break;
  29.                 case 13:
  30.                     System.out.print("  K");
  31.                     break;
  32.                 case 14:
  33.                     System.out.print("  A");
  34.                     break;
  35.                 default:
  36.                     System.out.printf("%3d", face);
  37.                     break;
  38.                 }
  39.  
  40.                 switch (suit) {
  41.                 case 0:
  42.                     System.out.print(clubs);
  43.                     break;
  44.                 case 1:
  45.                     System.out.print(diamonds);
  46.                     break;
  47.                 case 2:
  48.                     System.out.print(hearts);
  49.                     break;
  50.                 case 3:
  51.                     System.out.print(spades);
  52.                     break;
  53.  
  54.                 default:
  55.                     break;
  56.                 }
  57.             }
  58.  
  59.             System.out.println();
  60.         }
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement