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 に答える