coasterka

#6PrintFullDeckOfCards

Mar 29th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class PrintFullDeckOfCards
  5. {    
  6.     static void Main()
  7.     {
  8.         /*Write a program that generates and prints all possible cards from a standard deck of 52 cards (without the jokers).
  9.          * The cards should be printed using the classical notation (like 5♠, A♥, 9♣ and K♦). The card faces should start
  10.          * from 2 to A. Print each card face in its four possible suits: clubs, diamonds, hearts and spades. Use 2 nested
  11.          * for-loops and a switch-case statement.*/
  12.  
  13.         Console.OutputEncoding = Encoding.UTF8;
  14.        
  15.         char clubs = '\u2663';
  16.         char diamonds = '\u2666';
  17.         char hearts = '\u2665';
  18.         char spades = '\u2660';
  19.  
  20.         char[] suits = new char[] { clubs, diamonds, hearts, spades };
  21.  
  22.         string jack = "J";
  23.         string queen = "Q";
  24.         string knight = "K";
  25.         string ace = "A";
  26.  
  27.         for (int i = 2; i <= 14; i++)
  28.         {            
  29.             for (int j = 1; j <= 4; j++)
  30.             {
  31.                 switch (i)
  32.                 {
  33.                     case 2:
  34.                     case 3:
  35.                     case 4:
  36.                     case 5:
  37.                     case 6:
  38.                     case 7:
  39.                     case 8:
  40.                     case 9:
  41.                     case 10:
  42.                         {
  43.                             Console.Write(i + "{0} ", suits[j - 1]);
  44.                             break;
  45.                         }
  46.                     case 11: Console.Write(jack + "{0} ", suits[j - 1]); break;
  47.                     case 12: Console.Write(queen + "{0} ", suits[j - 1]); break;
  48.                     case 13: Console.Write(knight + "{0} ", suits[j - 1]); break;
  49.                     case 14: Console.Write(ace + "{0} ", suits[j - 1]); break;
  50.                 }
  51.             }
  52.             Console.WriteLine();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment