Advertisement
Jhonny_V

Print Deck of Cards/Telerik

Sep 28th, 2020
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.     //Scanner card sign
  6.         Scanner s = new Scanner(System.in);
  7.         String input = s.nextLine();
  8.         //create string of all card signs
  9.         String strCards = "2 3 4 5 6 7 8 9 10 J D K A";
  10.         //create array of strings with card signs
  11.         String [] cardSigns = strCards.split(" ");
  12.         //create array of all card suits
  13.         String [] suits = {"spades","clubs","hearts","diamonds"};
  14.  
  15.         //iterate through array of suits up to scanned sign included
  16.         for(String card:cardSigns){
  17.             //nest iteration with suits for every sign
  18.             for(String suit: suits){
  19.                 //no coma after last suit
  20.                 if (suit.equals( "diamonds")){
  21.                System.out.print(card + " of "+ suit);}
  22.                 else {
  23.                    System.out.print(card + " of "+ suit+", ");
  24.                     }
  25.             }
  26.             //when reach card sign equal to input sign we stop iterating
  27.             if (card.equals(input) ){
  28.                 break;
  29.             }
  30.             System.out.println();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement