posts - 23, comments - 6, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          java固定數(shù)組如何隨機(jī)輸出

          Posted on 2006-11-29 16:01 小傻 閱讀(461) 評(píng)論(0)  編輯  收藏 所屬分類: jsp

          import java.util.Random;
          public class test2 {
          ?public static void main(String args[]) {
          ??RandomTest();
          ?}
          ?
          ?// 數(shù)組自由排列
          ?public static void RandomTest(){
          ??Random ran = new Random();
          ??int a[] = { 1, 2, 3, 4, 5 ,6,7,8,9};
          ??int b[] = new int[a.length];
          ??int w = a.length;
          ??int x = 0;
          ??int y;
          ??
          ??for (int i = 0; i < a.length; i++) {??
          ???y = 0;
          ???x = Math.abs(ran.nextInt()) % w;
          ???// 把隨機(jī)選中的數(shù),提出來,然后省下數(shù)重新排列數(shù)組
          ???for (int j = 0; j < w; j++) {
          ????if (x == j) {
          ?????b[i] = a[x];
          ?????continue;15:59:4715:59:582006年11月29日
          ????}
          ????a[y] = a[j];
          ????y++;
          ???}
          ???w--;
          ???System.out.print("~" + b[i] + "~");
          ??}
          ?}
          }

          主站蜘蛛池模板: 奉新县| 扬州市| 贵德县| 镇赉县| 思茅市| 都安| 内黄县| 浦北县| 莱西市| 浠水县| 灯塔市| 临夏县| 清原| 儋州市| 商水县| 定兴县| 都江堰市| 九龙坡区| 和林格尔县| 克拉玛依市| 通许县| 剑川县| 安泽县| 中江县| 凤台县| 聊城市| 精河县| 浮山县| 岳池县| 丁青县| 迭部县| 山西省| 阿拉善盟| 连江县| 汪清县| 吉木萨尔县| 龙游县| 鞍山市| 乌鲁木齐县| 乌苏市| 锦屏县|