How to output suits of cards

Posted on 2003-03-10
Medium Priority
Last Modified: 2010-03-31
I want to output the characters for the suits of cards
to the console.  If that is possible, how do I do it
Question by:castello
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8107744
Do you mean the DOS extended ASCII characters?

If so, Java is not the way to go for a DOS-dependent program.


Expert Comment

ID: 8107881
codes 3, 4, 5 and 6 are hearts, diamonds, clubs and spades. the first and last might be the other way round, because on DOS if you press ctrl D it equates to ascii 4, but ctrl-c has a special function and crtl-f also. try typing "echo " then crtl-d, then enter. it should show a diamond. but i agree with jcaldwel, a dependency on DOS is probably not a good idea, although i would be interested to know what representations these characters have on other systems...
hope this is what you were looking for

Accepted Solution

Bob_Everard earned 200 total points
ID: 8225886
Do you mean something like this?  Very primitive, but...

public class suits {
   public static void main( String[] args ) {
      byte[] suits = { 0x03, 0x04, 0x05, 0x06 };
      char[] cards = { 'A', '2', '3', '4', '5', '6', '7', '8', '9',
                       'T', 'J', 'Q', 'K' };
      for ( int s = 0; s < suits.length; s++ ) {
         StringBuffer sb = new StringBuffer();
         for ( int c = 0; c < cards.length; c++ ) {
            sb.append( cards[ c ] + new String( suits, s, 1 ) + " ");
         } // for
         System.out.println( sb.toString() );
      } // for

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question