0

我正在尝试编写一个程序来处理我随机生成的一手牌。出于某种原因,我无法让它从我在主程序中的方法中打印字符串。我不确定我是否遗漏了某些东西,或者这一切都是错的,我对 Java 场景还是很陌生。这就是我得到的。

public class Deck {
  public static void main (String args[]) {
    Builder();
    out.println("Your hand is:" card )
  }
  // This will build the deck
  public static String Builder() {
    // I need this to pick from the random array
    Random r = new Random();

    // This is an array, to make one you need [] before string
    //This is how you get your ending
    String[] SuitsA = { "Hearts ",  "Diamonds ", "Spades ", "Clubs" };
    // The number array
    String[] FaceA = {"1","2","3","4","5","6","7","8","9","10","King ", "Queen ", "Jack ", "Ace ",};

    // Picks a random set from the arrays 
    String suit = SuitsA[r.nextInt(4)]; 
    String face = FaceA[r.nextInt(14)];

    //Tryng to make 1 string to return
    String card = ( suit + " of " + face ); 
    // This might give me a value to use in the method below
    out.println( card );
    return;
  }
}
4

1 回答 1

2

您没有从您的方法返回您的计算卡值(字符串)。所以像这样返回那个字符串

 String card = ( suit + " of " + face ); 
    // This might give me a value to use in the method below
 return card;

main并在方法中使用它

public static void main (String args[]) {
String value=Builder();
out.println("Your hand is:"+ value )
}
于 2013-04-08T22:43:00.357 回答