欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

java和js实现的洗牌小程序

时间:2022-11-03 10:31:32|栏目:JavaScript代码|点击:

这几天刚学了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]);
 }
 }
}

总结

上一篇:js导出Excel表格超出26位英文字符的解决方法ES6

栏    目:JavaScript代码

下一篇:javascript单张多张图无缝滚动实例代码

本文标题:java和js实现的洗牌小程序

本文地址:http://www.codeinn.net/misctech/218072.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有