Advertisement
Guest User

Untitled

a guest
Feb 14th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DeckCards {
  4.     public static void main(String[] args) {
  5.         //card faces from 2 to A
  6.         //print in its 4 possible suits: clubs, diamonds, hearts, spades
  7.         //use 2 nested for loops + switch-case statement
  8.  
  9.         Scanner input = new Scanner(System.in);
  10.         String n = input.nextLine();
  11.         String card = null;
  12.         String suits = null;
  13.         Integer nAsInt = Integer.parseInt(n);
  14.         for (int i = 2; i <= nAsInt; i++) {
  15.             switch (i) {
  16.                 case 2:
  17.                     card = "2 of ";
  18.                     break;
  19.                 case 3:
  20.                     card = "3 of ";
  21.                     break;
  22.                 case 4:
  23.                     card = "4 of ";
  24.                     break;
  25.                 case 5:
  26.                     card = "5 of ";
  27.                     break;
  28.                 case 6:
  29.                     card = "6 of ";
  30.                     break;
  31.                 case 7:
  32.                     card = "7 of ";
  33.                     break;
  34.                 case 8:
  35.                     card = "8 of ";
  36.                     break;
  37.                 case 9:
  38.                     card = "9 of ";
  39.                     break;
  40.                 case 10:
  41.                     card = "10 of ";
  42.                     break;
  43.                 case 11:
  44.                     card = "J of ";
  45.                     break;
  46.                 case 12:
  47.                     card = "Q of ";
  48.                     break;
  49.                 case 13:
  50.                     card = "K of ";
  51.                     break;
  52.                 case 14:
  53.                     card = "A of ";
  54.                     break;
  55.             }
  56.  
  57.             for (int j = 1; j<=4; j++){
  58.                 switch (j) {
  59.                     case 1:
  60.                         suits="clubs";
  61.                         break;
  62.                     case 2:
  63.                         suits="diamonds";
  64.                         break;
  65.                     case 3:
  66.                         suits="hearts";
  67.                         break;
  68.                     case 4:
  69.                         suits="spades";
  70.                         break;
  71.                 }
  72.  
  73.                 System.out.print(card + suits);
  74.                 if (j < 4) {
  75.                     System.out.print(", ");
  76.                 } else {
  77.                     System.out.println();
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement