JAVA扑克牌随即五张(数组实现)

java实现扑克牌随即五张:红桃,方块,黑桃,梅花;

import java.util.Arrays;
import java.util.Random;
public class PuKePai {
public static void main(String[] args) {
System.out.println(Arrays.toString(puke()));
}

public static String[] puke() {

String[] pool = { "红桃A", "红桃2", "红桃3", "红桃4", "红桃5", "红桃6", "红桃7",
"红桃8", "红桃9", "红桃10", "红桃J", "红桃Q", "红桃K", "方块A", "方块2", "方块3",
"方块4", "方块5", "方块6", "方块7", "方块8", "方块9", "方块10", "方块J", "方块Q",
"方块K", "黑桃A", "黑桃2", "黑桃3", "黑桃4", "黑桃5", "黑桃6", "黑桃7", "黑桃8",
"黑桃9", "黑桃10", "黑桃J", "黑桃Q", "黑桃K", "梅花A", "梅花2", "梅花3", "梅花4",
"梅花5", "梅花6", "梅花7", "梅花8", "梅花9", "梅花10", "梅花J", "梅花Q", "梅花K",
"大王", "小王" };

boolean used[] = new boolean[pool.length];
String pai[] = new String[5];
Random rd = new Random();

int i = 0;
while (true) {
int index = rd.nextInt(pool.length);
if (used[index])
continue;
pai[i++] = pool[index];
used[index] = true;

if (i == pai.length)
break;
}

return pai;
}
}

相关文章:

1、Java随机一注双色球代码
https://www.onexin.net/languages/the-java-random-a-note-color-ball-code/

2、高性能、高流量Java Web站点打造的22条建议(转)
https://www.onexin.net/java/high-performance-high-traffic-sites-to-build-java-web-22-recommendations-rpm/

3、Java开源缓存框架介绍
https://www.onexin.net/java/java-open-source-caching-frameworks-introduced/

4、JAVA程序命名规范
https://www.onexin.net/languages/java-program-naming-conventions/

5、PHP描述冒泡排序和快速排序算法
https://www.onexin.net/languages/php-description-of-bubble-sort-and-quicksort-algorithm/

转载请注明出处:https://www.onexin.net/languages/java-poker-then-five-array-implementation/

Leave a Reply

Your email address will not be published. Required fields are marked *