android 扑克牌框架,2020-03-24Android开发——扑克牌poker

具体的理解已在程序之中进行了注释

public class poker {

String dot;//记录点数

String pic;//记录花色

}

public static void main(String[] args) {

{

//生成一副牌

//准备一个数组保存所有的点数

String[] dots = new String[]{

"2", "3", "4", "5",

"6", "7", "8", "9" +

"", "10", "J", "Q",

"K", "A"};

//花色

String[] pics = new String[]{"♣", "♠", "♥", "♦"};

//數組保存所有的撲克牌

poker[] pokers = new poker[52];

int index = 0;

for (String dot : dots){//数组的遍历,会使得数组dot的形式进行遍历

for (String pic : pics) {

//創建一個撲克牌

poker poker = new poker();//創建一個poker對象,使用我們所定義的類之中的變量

poker.dot = dot;

poker.pic = pic;//这样使得内部循环的时候,点数不变,花色遍历形成四种组合

pokers[index] = poker;//因爲此時pokers[]和poker屬於同種型,可以进行相互的赋值,此时使得

//poker[]数组之中拥有了poker对象之中变量的赋值

index++;

}//拥有了所有的组合,并且赋值给了pokers数组

}

//輸出所有的牌

for (poker temp : pokers) {//数组的遍历,将pokers数组之中的数用同种类型的temp输出

System.out.print(temp.pic +temp.dot+ " ");

}

}

}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值