*7.29 (Game: pick four cards) Write a program that picks four cards from a deck of 52 cards and computes their sum. An Ace, King, Queen, and Jack represent 1, 13, 12, and 11, respectively. Your program should display the number of picks that yields the sum of 24.
public class ProgrammingEx7_29 { public static void main(String[] args) { int sum = 0, numberOfPick = 0; while (sum != 24) { sum = pickCard() + pickCard() + pickCard() +pickCard(); numberOfPick++; } System.out.println("Number of picks:" + numberOfPick*4); } public static int pickCard() { int card = (int) (Math.random() * 52.0); // pick a card 0-51 return card; } public static int getRank(int card) { return card / 4 + 1; // determine the rank 1-13 } }
ReplyDeletepublic static int getRank(int card) {
return card / 4 + 1; // determine the rank 1-13
}
i think this wrong to get rank return card % 13 // 0-->12