INTRODUCTION TO COMPUTER SCIENCE
Robert Sedgewick and Kevin Wayne


This is the syntax highlighted version of Cards.java.


/*************************************************************************
 *  Compilation:  javac Cards.java
 *  Execution:    java Cards
 *  
 *  Print out the 52 playing cards in order.
 *
 *  % java Cards
 *  Deuce of Clubs
 *  Three of Clubs
 *  Four of Clubs
 *  ...
 *  Ace of Spades
 *
 *************************************************************************/

public class Cards { 
    public static void main(String[] args) { 

        String[] suits = { "Clubs", "Diamonds", "Hearts", "Spades" };

        String[] ranks = { "Deuce", "Three", "Four", "Five", "Six",   "Seven",
                           "Eight", "Nine",  "Ten",  "Jack", "Queen", "King",  "Ace"
                         };

        for (int i = 0; i < suits.length; i++)
            for (int j = 0; j < ranks.length; j++)
                System.out.println(ranks[j] + " of " + suits[i]);
    }
}


Last updated: Wed Feb 11 18:16:34 EST 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.