zoukankan      html  css  js  c++  java
  • 数组输入

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication4
    {
        class Class1
        {
            int count;
            int[] list=new int[50];
            public void putin()
            {
                Console.Write("请输入你的数组元素,以空格隔开,以回车结束:");
                string str = Console.ReadLine();
                string[] result = str.Split(' ');
                int[] myArray = new int[result.Length];
                count = myArray.Length;
                for (int i = 0; i < myArray.Length; i++)
                {
                    list[i] = Convert.ToInt32(result[i]);
                }

            }
            public void cr()
            {
                Console.Write("请输入插入的位置:");
                int s = int.Parse(Console.ReadLine());
                for (int j = count; j >= s; j--)
                {
                    list[j + 1] = list[j];

                }
                Console.Write("请输入插入的数字:");
                list[s] = int.Parse(Console.ReadLine());
                count++;
            }
            public void del()
            {
                Console.Write("请输入删除的位置:");
                int s = int.Parse(Console.ReadLine());
                for (int j = s; j <count; j++)
                {
                    list[j] = list[j+1];

                }
                count--;
              
            }

            public void show()
            {
                for (int a = 0; a < count; a++)
                    Console.Write(list[a]+" ");
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication4
    {
        class Program
        {

            static void Main(string[] args)
            {
                Class1 c1 = new Class1();
                c1.putin();
                c1.show();
                //Console.Write("请选择:0.插入 1.删除");
                //int m = Console.Read();
                c1.cr();
                c1.show();
                c1.del();
                c1.show();
                Console.ReadKey();
            }
        }
    }


     

             
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    智能佳 金刚足球机器人 竞赛机器人 智能机器人
    DIY小能手|别买电动滑板车了,咱做一台吧
    !!2016/02/22——当日买入——事后追悔,总结经验,忘记了买票的初衷!
    20160222深夜 支撑与阻力的问题,突破要不要买,回踩要不要接
    2016/2/4——昨天操作错误
    C语言 · 瓷砖铺放
    C语言 · 字符串编辑
    C语言 · 比较字符串
    C语言 · 3000米排名预测
    C语言 · 陶陶摘苹果2
  • 原文地址:https://www.cnblogs.com/wuchao/p/2160783.html
Copyright © 2011-2022 走看看