如何生成一副Poker
import java.util.LinkedList;
import java.util.Random;
//扑克类
class Poker{
String color;//花色
String num;//点数
public Poker (String color,String num) {
this.color=color;
this.num =num;
}
public String toString() {
return "{"+color+num+"}";
}
}
public class Demo{
public static void main(String[] args) {
LinkedList<Poker> pokers=createPoker();
showPoker(pokers);
System.out.println("洗牌,洗牌。。。");
sufflePoker(pokers);
showPoker(pokers);
}
//生成一副扑克
public static LinkedList<Poker> createPoker() {
LinkedList<Poker> list=new LinkedList<Poker>();
String []color={"黑桃","红桃","梅花","方块"};
String []num={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
for (int i = 0; i < color.length; i++) {
for (int j = 0; j < num.length; j++) {
list.add(new Poker(color[i], num[j]));
}
}
return list;
}
//更好展示扑克
public static void showPoker(LinkedList<Poker> pokers){
for (int i = 0; i < pokers.size(); i++) {
System.out.print(pokers.get(i));
if (i%13==12) {
System.out.println();//换行
}
}
}
//洗扑克功能
public static void sufflePoker(LinkedList<Poker> pokers) {
Random random=new Random();//创建随机数对象
for (int i = 0; i < 100; i++) {//实现多次洗牌
//随机产生两个索引值
int index1=random.nextInt(pokers.size());
int index2=random.nextInt(pokers.size());
//根据索引值取出两张牌,然后交换两张牌的顺序
Poker poker1=pokers.get(index1);
Poker poker2=pokers.get(index2);
pokers.set(index1, poker2);
pokers.set(index2, poker1);
}
}
}
如何生成一副Poker的更多相关文章
- 音视频入门-12-手动生成一张PNG图片
* 音视频入门文章目录 * 预热 上一篇 [PNG文件格式详解]详细介绍了 PNG 文件的格式. PNG 图像格式文件由一个 8 字节的 PNG 文件署名域和 3 个以上的后续数据块(IHDR.IDA ...
- 输入一个正整数n,生成一张2的乘方表,输出2*0—2*n的值。
#include<stdio.h>#include<math.h> //程序中调用幂函数pow(),需包含头文件math.h//void main(){ int i,n; pr ...
- Python中 将数据插入到Word模板并生成一份Word
搬运出处: https://blog.csdn.net/DaShu0612/article/details/82912064
- 音视频入门-18-手动生成一张GIF图片
* 音视频入门文章目录 * GIF 编码知识 GIF 包含的数据块: 文件头(Header) 逻辑屏幕标识符(Logical Screen Descriptor) 全局颜色表(Global Color ...
- 网站统计中的数据收集原理及实现(share)
转载自:http://blog.codinglabs.org/articles/how-web-analytics-data-collection-system-work.html 网站数据统计分析工 ...
- 使用nginx lua实现网站统计中的数据收集
导读网站数据统计分析工具是各网站站长和运营人员经常使用的一种工具,常用的有 谷歌分析.百度统计和腾讯分析等等.所有这些统计分析工具的第一步都是网站访问数据的收集.目前主流的数据收集方式基本都是基于ja ...
- Jenkins+Gitlab搭建持续集成(CI)环境
利用Jenkins+Gitlab搭建持续集成(CI)环境 Permalink: 2013-09-08 22:04:00 by hyhx2008in intern tags: jenkins gitla ...
- Real-Rime Rendering (1) - 渲染管线(Rendering Pipeline)
提要 渲染管线是实时渲染中最重要的部分,它的最主要的任务就是在给定一个虚拟的场景,包括相机,object,灯光,纹理等等,生成一副2D的图像. 最基础的渲染管线如下图所示: 主要的阶段包括三个:App ...
- 关于Test--Pattern Generator IP核的测试
关于Test--Pattern Generator IP核的测试 1.Test--Pattern Generator 功能介绍 生成24-bit RGB视频流,此IP核可以用于系统测试,不需要先在片上 ...
随机推荐
- 代码审查工具 StyleCop 的探索
最近我们Advent Data Service (ADS) 在项目上需要按照代码规范进行代码的编写工作,以方便将来代码的阅读与维护. 但是人工检查起来容易遗漏或者格式不统一, ReSharper又是收 ...
- Citect:How do I translate Citect error messages?
http://www.opcsupport.com/link/portal/4164/4590/ArticleFolder/51/Citect To decode the error messag ...
- 简单的网页布局效果html5+CSS3
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Spring中的一个错误:使用Resources时报错(The annotation @Resources is disallowed for this location)
在学习Spring的过程中遇到一个错误:在使用注解@resources的时候提示:The annotation @Resources is disallowed for this location 后 ...
- 安装Ubuntu 14.04后要做的5件事情
转自安装Ubuntu 14.04后要做的5件事情 Ubuntu目前是世界上最流行的Linux操作系统,它提供了桌面版本和服务器版本,其他流行的Linux发行版本如Linux Mint也是基于Ubunt ...
- POJ2222+暴力搜索
一共2^15个状态 比较简单 /* 2^15 states */ #include<stdio.h> #include<string.h> #include<stdlib ...
- java路径中的空格问题(转)
java路径中的空格问题 1. URLTest.class.getResource("/").getPath(); URLTest.class.getResource(" ...
- 关于fastclick.js
Fastclick fastclick.js解决了什么问题? 自己接触WebApp开发的前期, 总感觉WebApp上的按键操作不如NativeApp的灵敏, 好像有那么一小点延迟. 后来才知道, 这是 ...
- Android:WebView深入使用
webView = (WebView) findViewById(R.id.info_detail_webview); WebSettings webSettings = webView.getSet ...
- MySQL结果集处理
问题: 1. MySQL对查询的结果集如果返回,一次性还是每条?2. 客户端如何接收结果集? 1. 对于有返回结果集的查询,server端和client端交互的数据包由以下组成: p1:meta da ...