Reputation: 123
I am trying to make a program to deal you a hand of cards that I randomly generate. For some reason I can't get it to print the string from my method in the main program. I'm not sure if I'm missing something or if it's all just wrong, I'm rather new to the java scene. this is what I got.
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;
}
}
Upvotes: 0
Views: 27702
Reputation: 40970
You are not returning your calculate card value (string) from your method. So return that string like this
String card = ( suit + " of " + face );
// This might give me a value to use in the method below
return card;
and use it in main
method
public static void main (String args[]) {
String value=Builder();
out.println("Your hand is:"+ value )
}
Upvotes: 2