• 3月12日 数组


    数组:

    一维数组:

    第一种定义方式:

    int[] shuzu = new int[5];
                //shuzu[0] = 1;
                //shuzu[1] = 2;
                //shuzu[2] = 3;
                //shuzu[3] = 4;
                //shuzu[4] = 5;
                //Console.WriteLine(shuzu[4]);

    第二种定义方式:

    int[] shuzu = new int[]{1,2,3,4,5};

    //输入班级人数,根据人数,挨个输入成绩,求平均分;
                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);
                Console.ReadLine();

    二维数组:

    //二维数组
                //int[,] shuzu = new int[3, 4];//3个数组,每个数组有4个
                //int[,] shuzu = new int[,] { };

    //输入班级人数,将每个人的
                //语文、数学、英语成绩输入二维数组;
                Console.Write("输入班级人数");
                int a = int.Parse(Console.ReadLine());
                double[,] fen = new double[a, 3];
                for (int i = 0; i < a; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (j == 0)
                        {
                            Console.WriteLine("" + (i + 1) + "个人的语文成绩是:");
                        }
                        if (j == 1)
                        {
                            Console.WriteLine("" + (i + 1) + "个人的数学成绩是:");
                        }
                        if (j == 2)
                        {
                            Console.WriteLine("" + (i + 1) + "个人的英语成绩是:");
                        }
                        fen[i, j] = double.Parse(Console.ReadLine());
                    }
                }
                Console.ReadLine();
     string [,] shuzu = new string[7,7] 
                { 
    
                {"  ","  ","  ",""," "," "," "},
                {"  ","  ",""," ",""," "," "},
                {"  ",""," ",""," ",""," "},
                {"  ","  ","  ",""," "," "," "},
                {"  ","  ","","",""," "," "},
                {"  ","  ","",""," "," "," "},
                {"  ","","","","",""," "},
                
    
                };
               for (int i = 0; i < 7; i++)
               {
                   for (int j = 0; j < 7; j++)
                   {
                       Console.Write(shuzu[i, j]);
                   };
                   Console.WriteLine();
               }
               Console.ReadLine();
                

    三维数组:

    //三维数组
                //int[, ,] shuzu = new int[3, 2, 4];//3个二维数组,每个二维数组有2个一维数组,每个一维数组有4个数据

  • 相关阅读:
    mac 系统安装selenium注意事项
    (mac系统下)mysql 入门
    Mac系统下配置JAVA Maven Ant 环境变量
    解决mac 下mysql安装后root用户登录密码错误问题
    关于使用eclipse maven UpdateProject时报错,无法更新本地仓库的问题解决方案
    201920201学期20192403《网络空间安全专业导论》第一周学习总结
    与数值相关的全局方法 菜鸟
    Jquery插件开发 菜鸟
    Jquery对象和DOM对象Jquery API (1) 菜鸟
    新的一年,新的生活
  • 原文地址:https://www.cnblogs.com/dongqiaozhi/p/5269277.html
Copyright © 2020-2023  润新知