我正在尝试制作一个程序来处理你随机生成的牌。由于某种原因,我不能让它从主程序中的方法打印字符串。我不确定我是否遗漏了某些内容,或者这些都是错的,我对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;
}
}
答案 0 :(得分: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 )
}