zoukankan      html  css  js  c++  java
  • 生产1100不重复随机数并排序

    using System;
    using System.Collections;

    namespace ConsoleApplication1
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    int temp = 0;
                
    int[] intArr = new int[100];
                ArrayList myList 
    = new ArrayList();
                Random rnd 
    = new Random();
                
    while (myList.Count < 100)
                {
                    
    int num = rnd.Next(1101);
                    
    if (!myList.Contains(num))    // 这句是关键
                        myList.Add(num);
                }

                
    //
                
    //  转换为整形数组
                
                
    for (int i = 0; i < 100; i++)
                    intArr[i] 
    = (int)myList[i];

                
    //
                
    //  排序
                
                
    for (int i = 0; i < intArr.Length-1; i++)
                {
                    
    for (int j = 0; j < intArr.Length-1; j++)
                    {
                        
    if(intArr[j] > intArr[j+1])
                        {
                            temp 
    = intArr[j + 1];
                            intArr[j 
    + 1= intArr[j];
                            intArr[j] 
    = temp;
                        }
                    }
                }

                
    //
                
    //  输出

                
    for (int i = 0; i < intArr.Length; i++)
                {
                    Console.WriteLine(intArr[i].ToString());
                    
                }
                Console.Read();

            }
        }
    }
  • 相关阅读:
    mysql data type <----> java data type (数值)
    line number is important in Exceptions.
    dom4j 使用原生xpath 处理带命名空间的文档
    dom4j 通过 org.dom4j.XPath 设置命名空间来支持 带namespace 的 xpath
    dom4j 创建一个带命名空间的pom.xml 文件
    xml to xsd ; xsd to xml
    sax 动态切换 抓取感兴趣的内容(把element当做documnet 处理)
    d3.js <一>
    python学习进阶一
    Java *字格
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1435755.html
Copyright © 2011-2022 走看看