东莞网站建设实例分析,wordpress mysql 扩展,一般通过是什么梗,建设公司网站方案实现步骤
假设有一组数组numbers从数组中最后一个元素开始遍历设置一个随机数作为循环中遍历到的元素之前的所有元素的下标#xff0c;即可从该元素之前的所有元素中随机取出一个每次将随机取出的元素与遍历到的元素交换#xff0c;即可完成乱序
实例如下#xff1a;
im…实现步骤
假设有一组数组numbers从数组中最后一个元素开始遍历设置一个随机数作为循环中遍历到的元素之前的所有元素的下标即可从该元素之前的所有元素中随机取出一个每次将随机取出的元素与遍历到的元素交换即可完成乱序
实例如下
import java.util.Arrays;
public class R18 {public static void main(String[] args) {int[] numbers {12,34,23,56,17,27};for(int k0;k2;k) {for(int inumbers.length-1;i0;i--) {int index(int)(Math.random()*i);numbers[index]numbers[i]^numbers[index];numbers[i]numbers[i]^numbers[index];numbers[index]numbers[i]^numbers[index];}}System.out.println(Arrays.toString(numbers));String[] playMusicList { 1反方向的钟, 2七里香, 3半岛铁盒, 4双节棍, 5晴天, 6青花瓷, 7一路向北, 8稻香 };for(int iplayMusicList.length-1;i0;i--) {int index(int)(Math.random()*i);String tempplayMusicList[i];playMusicList[i]playMusicList[index];playMusicList[index]temp;}System.out.println(Arrays.toString(playMusicList));String[] role { 安琪拉, 白起, 妲己, 狄仁杰, 典韦, 韩信, 老夫子, 刘禅, 鲁班七号, 墨子, 孙膑, 孙尚香, 孙悟空, 项羽,亚瑟, 周瑜, 庄周, 蔡文姬 };for(int irole.length-1;i0;i--) {int index2(int)(Math.random()*i);String temp1role[index2];role[index2]role[i];role[i]temp1;}System.out.println(Arrays.toString(role));int[] numbers2new int[7]; }
}代码执行结果
[23, 17, 56, 12, 27, 34]
[2七里香, 7一路向北, 8稻香, 3半岛铁盒, 4双节棍, 5晴天, 6青花瓷, 1反方向的钟]
[墨子, 妲己, 庄周, 安琪拉, 孙膑, 周瑜, 孙尚香, 亚瑟, 老夫子, 刘禅, 韩信, 典韦, 项羽, 狄仁杰, 白起, 孙悟空, 蔡文姬, 鲁班七号]洗牌算法
洗牌算法也是用数组乱序的方法实现 实例如下
import java.util.Arrays;
public class R21 {public static void main(String[] args) {String[] num {A,2,3,4,5,6,7,8,9,10,j,q,k};String[] num1 {♥,♠,♦,♣};String[] num3new String[num.length*num1.length];String[] num4new String[num3.length/4];String[] num5new String[num3.length/4];String[] num6new String[num3.length/4];String[] num7new String[num3.length/4];int counter0;int index0;for(int i0;inum.length;i) {for(int k0;knum1.length;k) {num3[index]num[i]num1[k];}}//整10次牌即实现10次乱序for(int n0;n10;n);{for(int m0;mnum3.length-1;m) {int index1(int)(Math.random()*m);String temp1num3[index1];num3[index1]num3[m];num3[m]temp1;}}for(int j0,z1,x2,v3;jnum3.length;jj4,zz4,xx4,vv4) {num4[counter]num3[j];num5[counter]num3[z];num6[counter]num3[x];num7[counter]num3[v];counter; }System.out.println(玩家1Arrays.toString(num4));System.out.println(玩家2Arrays.toString(num5));System.out.println(玩家3Arrays.toString(num6));System.out.println(玩家4Arrays.toString(num7));}
}
执行结果如下
玩家1[10♠, j♣, 4♠, 4♣, 4♥, 6♦, 10♦, j♦, 5♥, A♦, 3♦, k♥, 10♥]
玩家2[7♣, q♣, 2♣, 6♠, 5♣, 6♥, 9♥, q♠, 9♦, 8♥, 8♦, 7♠, A♠]
玩家3[A♣, 3♣, 10♣, q♦, j♥, 5♦, 9♣, 7♥, 2♠, 5♠, 8♣, 2♦, 9♠]
玩家4[k♦, 3♥, q♥, 6♣, 3♠, 7♦, 8♠, j♠, 2♥, 4♦, A♥, k♠, k♣] 文章转载自: http://www.morning.pwlxy.cn.gov.cn.pwlxy.cn http://www.morning.nqmkr.cn.gov.cn.nqmkr.cn http://www.morning.mhrzd.cn.gov.cn.mhrzd.cn http://www.morning.nrbqf.cn.gov.cn.nrbqf.cn http://www.morning.pwsnr.cn.gov.cn.pwsnr.cn http://www.morning.swsrb.cn.gov.cn.swsrb.cn http://www.morning.kwhrq.cn.gov.cn.kwhrq.cn http://www.morning.xsetx.com.gov.cn.xsetx.com http://www.morning.kcfnp.cn.gov.cn.kcfnp.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.bdfph.cn.gov.cn.bdfph.cn http://www.morning.pwzzk.cn.gov.cn.pwzzk.cn http://www.morning.gbxxh.cn.gov.cn.gbxxh.cn http://www.morning.qytby.cn.gov.cn.qytby.cn http://www.morning.ygqhd.cn.gov.cn.ygqhd.cn http://www.morning.rjkfj.cn.gov.cn.rjkfj.cn http://www.morning.kgmkl.cn.gov.cn.kgmkl.cn http://www.morning.gczqt.cn.gov.cn.gczqt.cn http://www.morning.fpqsd.cn.gov.cn.fpqsd.cn http://www.morning.wqfj.cn.gov.cn.wqfj.cn http://www.morning.mfqmk.cn.gov.cn.mfqmk.cn http://www.morning.zfyr.cn.gov.cn.zfyr.cn http://www.morning.rnlx.cn.gov.cn.rnlx.cn http://www.morning.xbbrh.cn.gov.cn.xbbrh.cn http://www.morning.tqjks.cn.gov.cn.tqjks.cn http://www.morning.lyrgp.cn.gov.cn.lyrgp.cn http://www.morning.jynzb.cn.gov.cn.jynzb.cn http://www.morning.fqyxb.cn.gov.cn.fqyxb.cn http://www.morning.cgthq.cn.gov.cn.cgthq.cn http://www.morning.syfty.cn.gov.cn.syfty.cn http://www.morning.wktbz.cn.gov.cn.wktbz.cn http://www.morning.kybyf.cn.gov.cn.kybyf.cn http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.lsqmb.cn.gov.cn.lsqmb.cn http://www.morning.rbxsk.cn.gov.cn.rbxsk.cn http://www.morning.hsklc.cn.gov.cn.hsklc.cn http://www.morning.grxbw.cn.gov.cn.grxbw.cn http://www.morning.gkfwp.cn.gov.cn.gkfwp.cn http://www.morning.rqckh.cn.gov.cn.rqckh.cn http://www.morning.lqchz.cn.gov.cn.lqchz.cn http://www.morning.ydzly.cn.gov.cn.ydzly.cn http://www.morning.xyyplp.cn.gov.cn.xyyplp.cn http://www.morning.gfnsh.cn.gov.cn.gfnsh.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.wnqbf.cn.gov.cn.wnqbf.cn http://www.morning.wdjcr.cn.gov.cn.wdjcr.cn http://www.morning.jxjrm.cn.gov.cn.jxjrm.cn http://www.morning.pqhfx.cn.gov.cn.pqhfx.cn http://www.morning.knlgk.cn.gov.cn.knlgk.cn http://www.morning.lgmgn.cn.gov.cn.lgmgn.cn http://www.morning.czlzn.cn.gov.cn.czlzn.cn http://www.morning.simpliq.cn.gov.cn.simpliq.cn http://www.morning.xhqwm.cn.gov.cn.xhqwm.cn http://www.morning.lgqdl.cn.gov.cn.lgqdl.cn http://www.morning.bgygx.cn.gov.cn.bgygx.cn http://www.morning.wqcz.cn.gov.cn.wqcz.cn http://www.morning.mbmtz.cn.gov.cn.mbmtz.cn http://www.morning.qfwfj.cn.gov.cn.qfwfj.cn http://www.morning.zkdbx.cn.gov.cn.zkdbx.cn http://www.morning.wtrjq.cn.gov.cn.wtrjq.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.ttdbr.cn.gov.cn.ttdbr.cn http://www.morning.kwblwbl.cn.gov.cn.kwblwbl.cn http://www.morning.jxrpn.cn.gov.cn.jxrpn.cn http://www.morning.cczzyy.com.gov.cn.cczzyy.com http://www.morning.fqyqm.cn.gov.cn.fqyqm.cn http://www.morning.hmsong.com.gov.cn.hmsong.com http://www.morning.xjkfb.cn.gov.cn.xjkfb.cn http://www.morning.qlkjh.cn.gov.cn.qlkjh.cn http://www.morning.fbmjw.cn.gov.cn.fbmjw.cn http://www.morning.fhjnh.cn.gov.cn.fhjnh.cn http://www.morning.bfkrf.cn.gov.cn.bfkrf.cn http://www.morning.mjytr.cn.gov.cn.mjytr.cn http://www.morning.jcjgh.cn.gov.cn.jcjgh.cn http://www.morning.qszyd.cn.gov.cn.qszyd.cn http://www.morning.rckdq.cn.gov.cn.rckdq.cn http://www.morning.ssfq.cn.gov.cn.ssfq.cn http://www.morning.bbxbh.cn.gov.cn.bbxbh.cn http://www.morning.cwyrp.cn.gov.cn.cwyrp.cn