[英]Printing my Program Output to a Single Line instead of on Multiple Lines
i want try get my system print out all on one line, example "jack of hearts" "2 of clubs " "ace of hearts" 我想尝试将我的系统全部打印在一行上,例如“ jack of hearts”,“ 2 of clubs”,“ heartsace”
i can get it to print out "jack of hearts " some pointers would be a huge help, have only a few weeks experience with java, im using bluj to run and test 我可以得到它来打印出“ jack of heart”,一些指针将是一个巨大的帮助,只有几周的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
在同一行打印
您正在使用System.out.println
而不是System.out.print
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.