常用的网站建设程序有那些济宁网站建设公司

张小明 2026/1/13 0:36:54
常用的网站建设程序有那些,济宁网站建设公司,dz wordpress互通,个人博客网站教程一、算法结构1.我们需要Card类来定义卡牌卡牌需要一个rank#xff08;牌面数字#xff09;#xff0c;和一个suit#xff08;花色#xff09;注意要记得写一个toString方法public int rank;//牌面数字public String suit;//花色public Card(int rank, String suit) {this.…一、算法结构1.我们需要Card类来定义卡牌卡牌需要一个rank牌面数字和一个suit花色注意要记得写一个toString方法public int rank;//牌面数字 public String suit;//花色 public Card(int rank, String suit) { this.rank rank; this.suit suit; } public String toString() { return String.format([%s %d],suit,rank); }2.我们需要CardDemo类来定义方法拿牌洗牌发牌上面我们已经把卡牌制作好了接下来来拿牌2.1、拿牌也就是制作卡牌我们以52张牌为例我们先定义一个数组来放花色public static final String[] suits {♠,♣,♦,♥};这里制作牌有两种逻辑一种是以一个数字来遍历4种花色另一种是用一个花色来定义13个数字我们采用第一种我们的对象的类型是Card 所以这里是ListCardpublic ListCard buyCard(){ ListCard cardList new ArrayList(); for (int i 1; i 13 ; i) {//把每个数字取出来进行花色遍历 for (int j 0; j 4; j) { int rank i;//拿数字 String suit suits[j];//拿花色 Card card new Card(rank,suit);//拿到属性制作出一张牌 cardList.add(card);//把牌放到数组中 } } return cardList;//形成一副52张牌的数组 }2.2、洗牌洗牌我们要用到Random类用来生成随机数public void shuffle(ListCard cardList){ Random random new Random(); for (int i cardList.size()-1; i 0; i--) { int index random.nextInt(i);//生成比i小的随机数 swap(cardList,index,i);//生成i下标的值和index下标的值交换实现洗牌 } } private void swap(ListCard cardList,int i , int j){ Card tmp cardList.get(i); cardList.set(i,cardList.get(j)); cardList.set(j,tmp); }2.3发牌我们以三个人玩牌一人发五张牌为例public ListListCard play(ListCard cardList){ //定义三个对象来拿牌 ListCard hand0 new ArrayList(); ListCard hand1 new ArrayList(); ListCard hand2 new ArrayList(); //里面有两个数组所以我们使用二维数组ListListCard ListListCard hand new ArrayList(); hand.add(hand0); hand.add(hand1); hand.add(hand2); for (int i 0; i 5; i) { for (int j 0; j 3; j) { Card card cardList.remove(i);//每发一张就把最上面的牌给到另一个Card对象并在原来的牌堆中删除 hand.get(j).add(card);//把牌挨个放回开始定义的三个对象的手中。 } } return hand;//返回二维数组。 }二、总结代码总结Card类package fisherYates; public class Card { //定义扑克牌 public int rank;//牌面数字 public String suit;//花色 public Card(int rank, String suit) { this.rank rank; this.suit suit; } public String toString() { return String.format([%s %d],suit,rank); } }CardDemo类package fisherYates; import java.util.ArrayList; import java.util.List; import java.util.Random; public class CardDemo { public static final String[] suits {♠,♣,♦,♥}; public ListCard buyCard(){ ListCard cardList new ArrayList(); for (int i 1; i 13 ; i) { for (int j 0; j 4; j) { int rank i; String suit suits[j]; Card card new Card(rank,suit); cardList.add(card); } } return cardList; } public void shuffle(ListCard cardList){ Random random new Random(); for (int i cardList.size()-1; i 0; i--) { int index random.nextInt(i); swap(cardList,index,i); } } private void swap(ListCard cardList,int i , int j){ Card tmp cardList.get(i); cardList.set(i,cardList.get(j)); cardList.set(j,tmp); } public ListListCard play(ListCard cardList){ ListCard hand0 new ArrayList(); ListCard hand1 new ArrayList(); ListCard hand2 new ArrayList(); ListListCard hand new ArrayList(); hand.add(hand0); hand.add(hand1); hand.add(hand2); for (int i 0; i 5; i) { for (int j 0; j 3; j) { Card card cardList.remove(i); hand.get(j).add(card); } } return hand; } }写完这个算法对泛型以及二维数组的使用有新的认识更能实际体验Java面向对象
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

网站免费做软件卖域名的公司 骗做网站

第一章:Open-AutoGLM 能干什么Open-AutoGLM 是一个面向自动化自然语言处理任务的开源框架,专为简化大语言模型(LLM)在实际业务场景中的应用而设计。它支持任务自动拆解、工具调用、多步推理与结果聚合,适用于复杂文本理…

张小明 2026/1/11 11:54:01 网站建设

自己做的网站如何加视频如何识别网站建设

想要在普通电脑上体验苹果系统吗?VMware Unlocker正是你需要的解决方案!这款开源工具专门解除macOS在非苹果硬件上的运行限制,让Windows和Linux用户都能轻松搭建macOS虚拟环境。无论你是开发者还是普通用户,都能通过简单的操作实现…

张小明 2026/1/10 4:56:54 网站建设

广州建设网站制作网站建设公司-跨界鱼科技

WinApps跨平台应用管理:从配置到排错的完整实战手册 【免费下载链接】winapps The winapps main project, forked from https://github.com/Fmstrat/winapps/ 项目地址: https://gitcode.com/GitHub_Trending/wina/winapps WinApps作为一款革命性的跨平台应用…

张小明 2025/12/30 12:33:21 网站建设

茂名模板建站定制网站建设的目的及效益分析

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 创建一个Python脚本,使用AI模型生成50000个有效的电子邮件地址。要求:1. 使用常见的域名(如gmail.com, yahoo.com等);2. …

张小明 2026/1/1 6:03:11 网站建设

2016网站备案网站建设颐高上海街

把Google Antigravity(或任何基于VS Code开源构建的编辑器)的插件市场切换为微软官方市场,需要将配置修改为以下官方API地址。 修改配置 请将设置页面中的对应字段修改为: Marketplace Item URL https://marketplace.visualstu…

张小明 2025/12/30 12:33:18 网站建设

欧洲手表网站青岛建设集团官方网站

终极指南:如何快速上手GNN模型解释器 【免费下载链接】gnn-model-explainer gnn explainer 项目地址: https://gitcode.com/gh_mirrors/gn/gnn-model-explainer GNN模型解释器(GNN-Model-Explainer)是一个强大的开源工具,专…

张小明 2026/1/1 6:03:20 网站建设