二维数组
定义方式:
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); //}
时间: 2024-10-23 21:25:22