zoukankan      html  css  js  c++  java
  • 关于数组基础的几道例题,非常实用,知识点很多。利用数组输出数据。

    第一道题:输出这三名字

    string[] name = new string[] {"梅西","卡卡","郑大世" };
                for (int i = 0; i < name.Length -1; i++)
                {
                    Console.Write(name[i]+" ");
                }
                Console.Write(name[name.Length -1]);
                Console.ReadLine();  

    第二道题:将一个整数数组的每一个元素进行处理,如果元素是正数,将这个元素加一,如果元素是负数,将这个元素再减一

    int[] shu=new int[]{1,3,5,-2,-3};
                for (int i = 0; i < shu.Length ; i++)
                {
                    if (shu[i]>0)
                    {
                        shu[i]++;
                    }
                    else if (shu[i]<0)
                    {
                        shu[i]--;
                    }
                }
                for (int i = 0; i < shu.Length ; i++)
                {
                    Console.WriteLine(shu [i]);
                 
                }                                  //小括号里定义变量,这个变量名只能在小括号内使用
                                                   //注意for 循环中i的作用域,除了这个作用域,i就不能用了
                         Console.ReadLine();*/

    第三道题:把一组字符串类型的元素进行反转

    string[] shu = new string[] {"你好","a","真的","皮球","干嘛","127" };
                         for (int i = 0; i < shu.Length/2; i++)  //在计算机中,7/2=3,因为是整数类型
                         {
                             string temp = shu[i];
                             shu[i] = shu[shu.Length - 1 - i];
                             shu[shu.Length - 1 - i] = temp;
                         }
                         for (int i = 0; i < shu.Length ; i++)
                         {
                             Console.WriteLine(shu[i]);
                         }
                         Console.ReadLine();

  • 相关阅读:
    【】Libevent源码解析
    sftp使用
    世界boss设计
    记一次薪酬谈判的教训 .
    一些常用的文件操作代码
    一位总经理的辞职信,以及回复
    JMeter安装、文档参考
    Charles——charles代理菜单proxy总结——external proxy 外部代理设置
    JDK安装
    Charles——charles常用功能——重定向
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4456216.html
Copyright © 2011-2022 走看看