zoukankan      html  css  js  c++  java
  • 数组和工具类练习

    1. 实现冒泡排序算法。

            int[]a1={34,12,66,43,5,98,44};
            for(int i=0;i<a1.length;i++)
            {
                for(int j=i+1;j<a1.length;j++)
                {
                    
                    if(a1[i]>a1[j])
                    {
                        
                        int zhong;
                        zhong=a1[i];
                        a1[i]=a1[j];
                        a1[j]=zhong;
                    }
                }
                System.out.print(" "+a1[i]+"");        
        }

    2.采用多种算法,模拟摇奖:从1-36中随机抽出8个不重复的数字

    int[] array = new int[8];
        for(int i=0;i<8;i++)
        {
            array[i]=(int) (Math.random()*36);
            for(int j=0;j<i;j++)
            {
                if(array[i]==array[j])
                {
                    i--;
                }
            }
            
        }
        for(int i=0;i<8;i++)
        {
            System.out.print(" "+" "+array[i]);
        }

        Random random = new Random();
        int []r= new int[8];
        for(int i=0;i<r.length;i++)
        {
            int temp = random.nextInt(36);
            if(temp==0)
                continue;
            for(int j:r)
        {
            if(j==temp)
            continue;
        }
            r[i]=temp;
            i++;
            
        }
        for(int i=0;i<8;i++)
        {
            System.out.print(" "+" "+array[i]);
        }

    看到她们快乐的晒,我就放心了,我要去炼淬了
  • 相关阅读:
    平板涂色
    速算游戏_NOI导刊2011提高(04)
    信息学奥赛一本通——配套刷题网站
    求10000以内n的阶乘
    大整数的因子
    计算2的N次方
    大整数加法
    带余除法
    A/B 高精度
    A*B 高静度
  • 原文地址:https://www.cnblogs.com/miracle-0807/p/5869577.html
Copyright © 2011-2022 走看看