2013-04-08 56 views
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; 
    } 
} 
+0

歡迎堆棧溢出。爲了將來的參考,你可能想用你正在使用的語言來標記你的問題。 – 2013-04-08 22:43:54

+0

這甚至不應該編譯,因爲你的方法沒有返回任何明確聲明返回'String'的方法。使用IDE(如Eclipse)來避免這樣的簡單問題 – syb0rg 2013-04-08 22:57:06

回答

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) 
} 
相關問題