gpt4 book ai didi

java - 将程序输出打印到单行而不是多行

转载 作者:行者123 更新时间:2023-12-01 12:17:38 26 4
gpt4 key购买 nike

我想尝试让我的系统在一行上打印出所有内容,例如“红心 jack ”“2 家具乐部”“红心王牌”

我可以打印出来“ jack 的心”一些指针将是一个巨大的帮助,只有几周的 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
} } }

}

最佳答案

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

关于java - 将程序输出打印到单行而不是多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26893045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com