码迷,mamicode.com
首页 > 编程语言 > 详细

C#部分---二维数组、split分割;

时间:2016-10-15 19:45:05      阅读:447      评论:0      收藏:0      [点我收藏+]

标签:

二维数组
定义方式:

int[,] array = new int[3, 4]{
{1,2,3,4},
{3,4,5,6},
{5,6,7,8}
};                  3表示,有三个一维数组
                     4表示,每一个一维数组中有4个元素。

split() 以***进行分割
分割开的内容需要放置在string类型的数组中,不需要给数组定义长度

string s = Console.ReadLine() ;
string[] array = s.Split(‘-‘);
foreach(string aa in array)
{
Console.WriteLine(aa);
}

输入班级人数,
//输入每个人的语数英成绩
//求语文两个最高分,数学两个最低分,英语平均分

 

 //Console.WriteLine("请输入班级人数:");
                //int n = int.Parse(Console.ReadLine());
                //double[,] chengji = new double[n, 3];
                //for (int i = 0; i < n; i++)
                //{
                //    Console.Write("请输入第{0}个学生语文的成绩:", (i + 1));
                //    chengji[i, 0] = double.Parse(Console.ReadLine());
                //    Console.Write("请输入第{0}个学生数学的成绩:", (i + 1));
                //    chengji[i, 1] = double.Parse(Console.ReadLine());
                //    Console.Write("请输入第{0}个学生英语的成绩:", (i + 1));
                //    chengji[i, 2] = double.Parse(Console.ReadLine());
                //}
                //for (int j = 0; j < n - 1; j++)
                //{
                //    for (int k = j + 1; k < n; k++)
                //    {
                //        if (chengji[j, 0] < chengji[k, 0])
                //        {
                //            double zhong = chengji[j, 0];
                //            chengji[j, 0] = chengji[k, 0];
                //            chengji[k, 0] = zhong;
                //            double zhong1 = chengji[j, 1];
                //            chengji[j, 1] = chengji[k, 1];
                //            chengji[k, 1] = zhong1;
                //            double zhong2 = chengji[j, 2];
                //            chengji[j, 2] = chengji[k, 2];
                //            chengji[k, 2] = zhong2;
                //        }
                //    }
                //}
                //Console.WriteLine("语文成绩最高的两位分别是{0},{1}", chengji[0, 0], chengji[1, 0]);
                //for (int w = 0; w < n - 1; w++)
                //{
                //    for (int y = w + 1; y < n; y++)
                //    {
                //        if (chengji[w, 1] < chengji[y, 1])
                //        {
                //            double zhong = chengji[w, 0];
                //            chengji[w, 0] = chengji[y, 0];
                //            chengji[y, 0] = zhong;
                //            double zhong1 = chengji[w, 1];
                //            chengji[w, 1] = chengji[y, 1];
                //            chengji[y, 1] = zhong1;
                //            double zhong2 = chengji[w, 2];
                //            chengji[w, 2] = chengji[y, 2];
                //            chengji[y, 2] = zhong2;
                //        }
                //    }
                //}
                //Console.WriteLine("数学成绩最低的两位分别是{0},{1}", chengji[n - 1, 1], chengji[n - 2, 1]);
                //double sum = 0;
                //for (int k = 0; k < n; k++)
                //{
                //    sum = sum + chengji[k, 2];
                //}
                //Console.WriteLine("英语平均分是:{0}", (sum / n));

 

//随意输入20个数字,放入数组,
////将数组中偶数索引上的值去除,放入另一个数组,然后打印出来

//Random ran=new Random();
                //int[]aa=new int[20];
                //int[]bb=new int[10];
                
                //for (int i = 0; i < 20;i++)
                //{
                //    aa[i] = ran.Next();
                //}
                //foreach(int cc in aa)
                //{
                //    Console.WriteLine(cc);
                //}
                //Console.Write("请按回车键继续。");
                //Console.ReadLine();
                //for (int j = 0; j < 10;j++ )
                //{
                //    bb[j]=aa[j*2+1];
                //}
                //foreach(int dd in bb)
                //{
                //    Console.WriteLine(dd);
                //}

 

C#部分---二维数组、split分割;

标签:

原文地址:http://www.cnblogs.com/xingyue1988/p/5965069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!