• 关于数组基础的几道例题,非常实用,知识点很多。利用数组输出数据。


    第一道题:输出这三名字

    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();

  • 相关阅读:
    Working with the RadioButton and CheclBox controls
    Simple Data Binding in Silverlight 4.0
    Data Binding in Silverlight 4.0
    Building a Simple DataGrid in Silverlight 4.0
    EXCEL数据导入SQL Server数据库中
    正则表达式必知必会
    Eclipse插件一次copy多个文件的相对路径路径
    走出软件作坊
    写在前面的话
    [转载]有经验的Java开发者和架构师容易犯的10个错误
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4456216.html
Copyright © 2020-2023  润新知