Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that generates and prints all possible cards from a standard deck
- * of 52 cards (without the jokers). The cards should be printed using the classical notation
- * (like 5♠, A♥, 9♣ and K♦). The card faces should start from 2 to A.
- * Print each card face in its four possible suits: clubs, diamonds, hearts and spades.
- * Use 2 nested for-loops and a switch-case statement. */
- import java.util.Locale;
- public class _04_PrintADeckOf52PlayCards {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Locale.setDefault(Locale.ROOT);
- char clubs = '\u2663';
- char diamonds = '\u2666';
- char hearts = '\u2665';
- char spades = '\u2660';
- for (int face = 2; face < 15; face++) {
- for (int suit = 0; suit < 4; suit++) {
- switch (face) {
- case 11:
- System.out.print(" J");
- break;
- case 12:
- System.out.print(" Q");
- break;
- case 13:
- System.out.print(" K");
- break;
- case 14:
- System.out.print(" A");
- break;
- default:
- System.out.printf("%3d", face);
- break;
- }
- switch (suit) {
- case 0:
- System.out.print(clubs);
- break;
- case 1:
- System.out.print(diamonds);
- break;
- case 2:
- System.out.print(hearts);
- break;
- case 3:
- System.out.print(spades);
- break;
- default:
- break;
- }
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement