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 cards are:");
for (int i = 0; i < 5; i++) {
PrintCard(player[i]);
}
System.out.print("\nThe computer's cards are:");
for (int i = 0; i < 5; i++) {
PrintCard(computer[i]);
}
switch (result) {
case 0:
System.out.print("\nYou and the computer are tied for the highest single card.");
break;
case 1:
System.out.print("\nYou has the highest single card.");
break;
case 2:
System.out.print("\nThe computer has the highest single card.");
break;
}
}
private static void PrintCard(int card) {
switch (card) {
case 11:
System.out.print("J ");
break;
case 12:
System.out.print("Q ");
break;
case 13:
System.out.print("K ");
break;
case 14:
System.out.print("A ");
break;
default:
System.out.print(card + " ");
}
}
void m() {
int[] personCard = new int[5];
int[] computerCard = new int[5];
int personCount = 0;
int computerCount = 0;
System.out.print("Your cards are: ");
for (int i = 0; i < 5; i++) {
personCard[i] = (int) (Math.random() * 13) + 2;
if (personCard[i] == 11) {
System.out.print("J" + "\t");
} else if (personCard[i] == 12) {
System.out.print("Q" + "\t");
} else if (personCard[i] == 13) {
System.out.print("K" + "\t");
} else if (personCard[i] == 14) {
personCount++;
System.out.print("A" + "\t");
} else {
System.out.print(personCard[i] + "\t");
}
}
System.out.println("\n");
System.out.print("The computer's cards are:");
for (int i = 0; i < 5; i++) {
computerCard[i] = (int) (Math.random() * 13) + 1;
if (computerCard[i] == 11) {
System.out.print("J" + "\t");
} else if (computerCard[i] == 12) {
System.out.print("Q" + "\t");
} else if (computerCard[i] == 13) {
System.out.print("K" + "\t");
} else if (computerCard[i] == 14) {
computerCount++;
System.out.print("A" + "\t");
} else {
System.out.print(computerCard[i] + "\t");
}
}
System.out.println("\n");
if (personCount > 0 && computerCount == 0) {
System.out.println("You has the highest single card");
} else if (personCount == 0 && computerCount > 0) {
System.out.println("The computer has the highest single card");
} else if (personCount == 0 && computerCount == 0) {
System.out.println("You and the computer are tied for the highest single card");
} else if (personCount > 0 && computerCount > 0) {
System.out.println("Both you and the computer have the highest single card");
}
}
}
蠢猪一个,发你一个了 不会玩??还来要
你是用于智能手机吗