• 数组分为一维数组,二维数组,多为数组


    //一维数组【相同数据类型】
                //第一种定义方式
                //int[] shuzu = new int[5];
                //for (int i = 0; i < 5; i++)
                //{
                //    shuzu[i] = i + 1;
                //}
                //    //索引从0开始
                //    //赋值
                //    //shuzu[0] = 1;
                //    //shuzu[1] = 2;
                //    //shuzu[2] = 3;
                //    //shuzu[3] = 4;
                //    //shuzu[4] = 5;
                //    ////shuzu[5] = 6;
                //    ////shuzu[6] = 7;
                //    Console.WriteLine(shuzu[4]);
    
    
                //第二种定义方式
                //int[] shuzu = new int[] { 1,2,3,4,5 };
                //Console.WriteLine(shuzu[2]);
    
    
    
    
                //从控制台输入10个人的年龄放入数组,
                //将十个人的年龄求总和
                //int [] age=new int [10];
                //int sum = 0;
                //for (int i = 0; i < 10; i++)
                //{
                //    Console.Write("请输入第"+(i+1)+"个人的年龄:");
                //    age[i] = int.Parse(Console.ReadLine());
                //    sum += age[i];
                //}
    
                //Console.WriteLine(sum);
    
                //输入人名放进数组,输出第5个人的姓名
                //Console.Write("请输入有几个人:");
                //int a = int.Parse(Console.ReadLine());
    
                //string [] name =new string [a];
                //for (int i = 0; i < a;i++ )
                //{
                //    Console.Write("请输入第" + (i + 1) + "个人的姓名:");
                //    name[i] = Console.ReadLine();
                //}
                //Console.WriteLine(name[4]);
    
    
    
                //输入班级人数,根据人数,
                //挨个输入成绩,求平均分
                //Console.Write("请输入班级人数:");
                //int a = int.Parse(Console.ReadLine());
                //double [] fen = new double [a];
                //double sum = 0;
                //for (int i = 0; i < a;i++ )
                //{
                //    Console.Write("请输入第"+(i+1)+"个人的分数:");
                //    fen[i] = double.Parse(Console.ReadLine());
                //    sum += fen[i];
                //}
    
                //Console.WriteLine("班级平均分为:"+sum/a);
    
    
                //二维数组
                //int[,] shuzu = new int[3, 4];
                //int[,] shuzu = new int[,] {
                //{1,2,3,4},
                //{5,6,7,8},
                //{6,7,8,9}
                //};
    
                //string[,] shuzu = new string[,] {
                //{"  ","■","■","■","■","■",""},
                //{"  ","  ","  ","■","","",""},
                //{"  ","  ","  ","■","","",""},
                //{"  ","  ","■","■","■","",""},
                //{"  ","  ","  ","■","  ","  ",""},
                //{"  ","  ","  ","■","  ","  ",""},
                //{"■","■","■","■","■","■","■"}
                //};
    
                //for (int i = 0; i < 7; i++)
                //{
                //    for (int j = 0; j < 7; j++)
                //    {
                //        Console.Write(shuzu[i, j]);
                //    }
                //    Console.WriteLine();
                //}
    
    
                //输入班级人数,将每个人的
                //语文,数学,英语成绩输入二维数组
                //Console.Write("请输入班级人数:");
                //int a = int.Parse(Console.ReadLine());
                //double [,] shuzu = new double [a,3];
    
                //for (int i = 0; i < a; i++)
                //{
                //    for (int j = 0; j < 3; j++)
                //    {
                //        if (j == 0)
                //        {
                //            Console.Write("请输入第"+(i+1)+"个人的语文成绩:");
                //        }
                //        if (j == 1)
                //        {
                //            Console.Write("请输入第" + (i + 1) + "个人的数学成绩:");
                //        }
                //        if (j == 2)
                //        {
                //            Console.Write("请输入第" + (i + 1) + "个人的英语成绩:");
                //        }
                //        shuzu[i, j] = double.Parse(Console.ReadLine());
                //    }
                //}
    
    
    
                //    Console.ReadLine();
    
    
    
                //三维数组
                //int[, ,] shuzu = new int[3, 2, 4];
    
                //{ 
                //    {
                //        {,,,},
                //        {,,,} 
                //    },
                //    {
                //        {,,,},
                //        {,,,}
                //    },
                //    {
                //        {,,,},
                //        {,,,}
                //    } 
                //};
     string[,] shuzu = new string[8, 7]{           
                    {"  ","  ","  ","■","","","" },
                    {"  ","  ","■","  ","■","","" },
                    {"  ","■","  ","■","  ","■","" } ,
                    {"■","  ","  ","■","  ","  ","■" },
                    {"  ","  ","  ","■","■","",""},
                    {"  ","■","  ","■","","","" }, 
                    {"  ","■","  ","■","","","" },
                    {"■","■","■","■","■","■","■" },
                };
    
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 7; j++)
                    {
                        Console.Write(shuzu[i, j]);
    
                    }
                    Console.WriteLine();
                }
    
    
    
    
    
  • 相关阅读:
    Tomcat环境的搭建(web基础学习笔记一)
    子查询二(在HAVING子句中使用子查询)
    子查询一(WHERE中的子查询)
    分组统计查询(学习笔记)
    Oracle体系结构一(学习笔记)
    表分区(学习笔记)
    索引(学习笔记)
    序列(学习笔记)
    触发器七(复合触发器)(学习笔记)
    触发器六(系统触发器)(学习笔记)
  • 原文地址:https://www.cnblogs.com/xingfudehuanyan/p/5269298.html
Copyright © 2020-2023  润新知