将我的程序输出打印到单行而不是多行

时间:2014-11-12 17:35:49

标签: java

我想尝试让我的系统在一行中打印出来,例如 “心中的杰克” “2个俱乐部” “心中的王牌”

我可以打印出来 “杰克 心中“ 一些指针将是一个巨大的帮助,只有几周的java经验,我使用bluj运行和测试

public class Cards {

    public static final int CARDS_IN_DECK = 52;
    public static final int SPADES = 0;
    public static final int HEARTS = 1;
    public static final int DIAMONDS = 2;
    public static final int CLUBS = 3;

    public static int deck[];  
    public static int deckSuit[];



    public static void main ()
    {

    {  int i; // counter
        int j;
        String value;

        createDeck();   // this is a function call

        // Show the cards in the deck
        System.out.println("Your hand is as follows:");
        for (i=0 ; i < 5; i++)
          // this is the loop for 5 card draw
         {

           if (deck[i]<=10 && deck[i]>1) // this is inbetween this range of numbers
              System.out.println(deck[i] + " of " + deckSuit[i]);

             if(deck[i]==11)
                System.out.println("jack" + " of " + deckSuit[i]);
            else if(deck[i]==12)
                System.out.println("queen" + " of " + deckSuit[i]);
            else if(deck[i]==13)
                System.out.println("king" + " of " + deckSuit[i]);
            else if(deck[i]==14)
                System.out.println("ace" + " of " + deckSuit[i]);

            if(deckSuit[i] == 0)
                System.out.println(" of " + "SPADES"); // i want to try and get a print out "jack of spades
             else if (deckSuit[i] == 1)
                System.out.println(" of " + "HEARTS");
             else if (deckSuit[i] == 2)
                System.out.println(" of " + "DIAMONDS");
             else if (deckSuit[i] == 3)
                System.out.println(" of " + "CLUBS");
                }
           }





    }

    // create the deck 
    //
    // deck[] contains the values of 52 cards
    // values 2 to 14
    // 2 - 10 are normal , 11 = Jack, 12 = Queen
    // 13 = King, 14 = Ace
    //
    // suit[] contains the values of the suits of the 52 cards
    // 0 Spades, 1 Hearts, 2 Diamonds, 3 Clubs
    //
    // so if deck[2] = 11 and suit[2] = 1
    // then that card would be the Jack of Hearts
    //     
    public static void createDeck()
    {
        int i,j, place;

        //

        //
        // create a deck of cards
        deck = new int[CARDS_IN_DECK];
        deckSuit = new int[CARDS_IN_DECK];
        // Populate the deck
        for (j=0; j<4 ; j++)    // the suits
        {
            for (i=2 ; i <= 14 ; i++) 
            // the cards
            {
                // find an empty place
                do
                {
                    place = (int)(Math.random()*CARDS_IN_DECK);     // 0 to 51             
                } while (deck[place] != 0);    
                deck[place] = i;    // store the card value
                deckSuit[place] = j;    // store the card suit
            }   }        }      

}

2 个答案:

答案 0 :(得分:1)

System.out.println在下一行打印输出,使用System.out.print在同一行打印

答案 1 :(得分:0)

您正在使用System.out.println而不是System.out.print