用Java for 编写关于扑克牌的程序!急!

来源:百度知道 编辑:UC知道 时间:2024/09/28 11:52:36
Use “for” loops to play a very simple version of poker where only the high card is checked. Print
five random cards for the user and five random cards for the computer. Card values should be displayed as
2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, or A, where A has the highest rank. Display a message indicating who has
the highest card, including the case of a tie. There is no user input for this problem.

Two examples of output:

Example A:
Your cards are: Q 3 9 8 6
The computer's cards are: 6 K A 8 9
The computer has the highest single card.

Example B:
Your cards are: 6 K 7 K 9
The computer's cards are: 10 8 8 K Q
You and the computer are tied for the highest single card.

这是题目,有高手过来帮忙解答一下。
我搞不清如何区别出最大的牌,如何表示A J Q K ,而且如何区别是电脑的还是我的也是个问题。。。

如果这样随机抽牌的话
System.out.print("Your cards are : ");
for (int i = 1; i <= 5; i++) {
int card = (int) (Mat

存储时可以用数字,最后显示时可以装换为字母
import java.util.Random;

public class Poker {
public static void main(String[] args) {
Random random = new Random();
int[] computer = new int[5];
int[] player = new int[5];
for (int i = 0; i < 5; i++) {// 发牌
computer[i] = random.nextInt(13) + 2;// 2到14的随机数,14表示A
player[i] = random.nextInt(13) + 2;// 2到14的随机数,14表示A
}
int result = Judge(player, computer);
Show(player, computer, result);
}

// 比较
private static int Judge(int[] player, int[] computer) {
int p = 0, c = 0;
for (int i = 0; i < 5; i++) {
if (14 == player[i])
p++;
if (14 == computer[i])
c++;
}
if (p > 0 && 0 == c)
return 1;
if (p == 0 && c > 0)
return 2;
return 0;

}

private static void Show(int[] player, int[] computer, int result) {
System.out.print("Your card