Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DeckCards {
- public static void main(String[] args) {
- //card faces from 2 to A
- //print in its 4 possible suits: clubs, diamonds, hearts, spades
- //use 2 nested for loops + switch-case statement
- Scanner input = new Scanner(System.in);
- String n = input.nextLine();
- String card = null;
- String suits = null;
- Integer nAsInt = Integer.parseInt(n);
- for (int i = 2; i <= nAsInt; i++) {
- switch (i) {
- case 2:
- card = "2 of ";
- break;
- case 3:
- card = "3 of ";
- break;
- case 4:
- card = "4 of ";
- break;
- case 5:
- card = "5 of ";
- break;
- case 6:
- card = "6 of ";
- break;
- case 7:
- card = "7 of ";
- break;
- case 8:
- card = "8 of ";
- break;
- case 9:
- card = "9 of ";
- break;
- case 10:
- card = "10 of ";
- break;
- case 11:
- card = "J of ";
- break;
- case 12:
- card = "Q of ";
- break;
- case 13:
- card = "K of ";
- break;
- case 14:
- card = "A of ";
- break;
- }
- for (int j = 1; j<=4; j++){
- switch (j) {
- case 1:
- suits="clubs";
- break;
- case 2:
- suits="diamonds";
- break;
- case 3:
- suits="hearts";
- break;
- case 4:
- suits="spades";
- break;
- }
- System.out.print(card + suits);
- if (j < 4) {
- System.out.print(", ");
- } else {
- System.out.println();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement