蝙蝠岛资源网 Design By www.hbtsch.com

这几天刚学了java和javascript,简单写了个用java和javascript的小程序

JavaScript的

// An highlighted block
var colors = ['红桃','梅花','方片','黑桃']
var numbers = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
var puke = new Array();
var cards = new Array();
for (var i = 0; i < 52; i++){
  cards[i] = i
}
console.log("洗牌前");
for (var i = 0; i < 52; i++) {
  puke [i] = colors[parseInt(cards[i]/13)]+numbers[cards[i]%13]

}
console.log(puke)
console.log("洗牌后")
puke.sort(function () {
  return 0.5-Math.random()
})
console.log(puke)

java的

public class Puke{
 public static void main(String[] args) {
 // TODO Auto-generated method stub
    String colors[] = {"黑桃","红桃","梅花","方片"};
    String words[] = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
    String[] cards = new String[52];
    System.out.println("洗牌前:\n");
    for (int i = 0; i < 52; i++) {
  cards[i] = colors[i/13] + words[i%13];
  if (i%13==0) {
  System.out.println();
  }
  System.out.print(" "+cards[i]);
 }
    System.out.println();
    System.out.println("洗牌后");
    String str;
    for(int i=0;i<cards.length;i++){
      int e=(int) Math.round((cards.length-1)*Math.random());
      str=cards[e];
      cards[e]=cards[cards.length-1];
      cards[cards.length-1]=str;
     }
    for (int i = 0; i < 52; i++) { 
  if (i%13==0) {
  System.out.println();
  }
  System.out.print(" "+cards[i]);
 }
 }
}

总结

以上所述是小编给大家介绍的java和js实现的洗牌小程序,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

标签:
js,洗牌小程序,java,洗牌小程序

蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com

评论“java和js实现的洗牌小程序”

暂无java和js实现的洗牌小程序的评论...