二維數組
定義方式:
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); //}