zoukankan      html  css  js  c++  java
  • 数组中插入1-100数字,数字不能重复.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                Random random = new Random();
                int[] array = new int[100];
    
                int i = 0;
                int index = 0;
                while(true)
                {
                    i = random.Next(1, 101);
                    if(!isExist(array,i))
                    {
                        array[index] = i;
                        index++;
                        if (index == 100) 
                        {
                            break;
                        }
                    }
    
                }
    
                Array.Sort(array);
                foreach (var k in array)
                {
                    Console.WriteLine(k);
                }
    
                Console.ReadKey();
            }
    
            //判断是否有重复的数字在数组里面
            public static bool isExist(int [] array,int n) 
            {
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] == n)
                    {
                        return true;
                    }
                 }
    
                return false; 
            } 
        }
    }
    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    组合继承
    包装明星——封装
    多种添加公用方法的方式
    专有扩展
    插入标记
    mac 命令操作
    php(apache)切换版本
    SqlServer索引+约束篇章
    sqlserver 常用语法
    C# 通用数据访问类
  • 原文地址:https://www.cnblogs.com/plateFace/p/4683511.html
Copyright © 2011-2022 走看看