課程
/后端開發(fā)
/C#
/C#開發(fā)輕松入門
一次考試,各位同學(xué)的姓名和分?jǐn)?shù)如下:
請編寫程序,輸出分?jǐn)?shù)最高的同學(xué)的姓名和分?jǐn)?shù)。運行效果如下:
2018-06-12
源自:C#開發(fā)輕松入門 6-1
正在回答
記錄下,最上面的二維數(shù)組的厲害了,
if(int.Parse(info[i,1])>int.Parse(info[temp,1]))//用parse轉(zhuǎn)換成整形,進行循環(huán)比較 temp初始為0,條件為真則temp值加1,第一次循環(huán)[0,1],和[0,1] 比較條件為false,i+1,而temp不變,之后 [(I)1,1]和[(temp)0,1]比較為真,temp變成1,之后i繼續(xù)循環(huán),temp變成2,循環(huán)終止后,temp還是2.
temp+1
打印的是temp值,
string[,] info = new string[8, 2] { { "吳松", "89" }, { "錢東宇", "90" }, { "伏晨", "98" }, { "陳陸", "56" }, { "周蕊", "60" }, { "林日鵬", "9" }, { "何昆", "93" }, { "關(guān)欣", "85" } };
? ? ? ? ? ? int temp=0;
? ? ? ? ? ? for(int i=0;i<info.GetLongLength(0);i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(int.Parse(info[i,1])>int.Parse(info[temp,1]))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? temp=i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分?jǐn)?shù)最高的是" + info[temp, 0] + ",分?jǐn)?shù)是" + info[temp, 1]);
string[,] a = new string[2, 8] { { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" }, { "89", "90", "98", "56", "60", "91", "93", "85" } };
? ? ? ? ? ? int record=0;
? ? ? ? ? ? int max=0;
? ? ? ? ? ? //獲取二維數(shù)組里面第二個數(shù)組的長度GetLength(1)
? ? ? ? ? ? for (int i = 0; i < a.GetLength(1); i++)
????????????//int.Parse強制轉(zhuǎn)換成int類型
? ? ? ? ? ? ? ? if (int.Parse(a[1, i]) > max)
? ? ? ? ? ? ? ? ? ? max = int.Parse(a[1, i]);
? ? ? ? ? ? ? ? ? ? record = i;
? ? ? ? ? ? Console.Write("分?jǐn)?shù)最高的是" + a[0, record] + ",分?jǐn)?shù)是" + a[1, record]);
你說的是用二維數(shù)組做出來嗎?像這樣?
string[] name = { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" };
? ? ? ? ? ? int[]score = { 89,90,98,56,60,91,93,85};
? ? ? ? ? ? int max = score[0];
? ? ? ? ? ? int record = 0;
? ? ? ? ? ? for (int i = 1; i < score.Length; i++) {
? ? ? ? ? ? ? ? if (score[i]>max) {
? ? ? ? ? ? ? ? ? ? max = score[i];
? ? ? ? ? ? ? ??
? ? ? ? ? ? Console.Write("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}" + name[record], max);
那個 親,首先謝謝您啊~~然后我再問下那個,我沒理解錯的話這個應(yīng)該是聲明的兩個數(shù)組的方式·~
親,你會那種聲明 string[,] a = new string[,]{~~~~~};
這種二維的嗎??
?string[] x = { "吳松", "錢東宇", "伏晨", "陳陸", "周陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" };
? ? ? ? ? ? int[] y = { 89, 90, 98, 56, 60, 91, 93, 85 };
? ? ? ? ? ? int max;
? ? ? ? ? ? max = 0;
? ? ? ? ? ? string name;
? ? ? ? ? ? name = null;
? ? ? ? ? ? for (int i = 0; i < y.Length; i++)
? ? ? ? ? ? ? ? if (y[i] > max || max == 0)
? ? ? ? ? ? ? ? ? ? max = y[i];
? ? ? ? ? ? ? ? ? ? name = x[i];
? ? ? ? ? ? Console.WriteLine("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}", name, max);
? ? ? ? ? ? Console.ReadLine();
? ? ? ? }
?????????? string[] a = new string[] { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" };??????????? int[] b = new int[] { 89, 90, 98, 56, 60, 91, 93, 85 };??????????? int max = 0;??????????? string name = null;??????????? for (int i = 0; i < b.Length; i++)??????????? {??????????????? if (b[i] > max)??????????????? {??????????????????? max = b[i];??????????????????? name = a[i];??????????????? }??????????? }??????????? Console.Write("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}", name, max);
定義一個string數(shù)組存放姓名,一個int數(shù)組存放成績,然后定義一個最大值max,用for循環(huán)嵌套if比較大小把最大值賦給max,并把最大值的索引給姓名數(shù)組。
舉報
本門課程是C#語言的入門教程,將帶你輕松入門.NET開發(fā)
3 回答這道題如果用二維數(shù)組的話該怎么作?
1 回答我用二維數(shù)組做的(菜鳥,勿噴)
1 回答二維數(shù)組
2 回答關(guān)于二維數(shù)組GetLength的用法
1 回答老師在嗎?用二維數(shù)組還是一維數(shù)組效率比較高呢?我現(xiàn)在用的是二維數(shù)組,代碼如下
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-07-09
記錄下,最上面的二維數(shù)組的厲害了,
if(int.Parse(info[i,1])>int.Parse(info[temp,1]))//用parse轉(zhuǎn)換成整形,進行循環(huán)比較 temp初始為0,條件為真則temp值加1,第一次循環(huán)[0,1],和[0,1] 比較條件為false,i+1,而temp不變,之后 [(I)1,1]和[(temp)0,1]比較為真,temp變成1,之后i繼續(xù)循環(huán),temp變成2,循環(huán)終止后,temp還是2.
temp+1
打印的是temp值,
2018-07-02
string[,] info = new string[8, 2] { { "吳松", "89" }, { "錢東宇", "90" }, { "伏晨", "98" }, { "陳陸", "56" }, { "周蕊", "60" }, { "林日鵬", "9" }, { "何昆", "93" }, { "關(guān)欣", "85" } };
? ? ? ? ? ? int temp=0;
? ? ? ? ? ? for(int i=0;i<info.GetLongLength(0);i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(int.Parse(info[i,1])>int.Parse(info[temp,1]))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? temp=i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分?jǐn)?shù)最高的是" + info[temp, 0] + ",分?jǐn)?shù)是" + info[temp, 1]);
2018-06-27
string[,] a = new string[2, 8] { { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" }, { "89", "90", "98", "56", "60", "91", "93", "85" } };
? ? ? ? ? ? int record=0;
? ? ? ? ? ? int max=0;
? ? ? ? ? ? //獲取二維數(shù)組里面第二個數(shù)組的長度GetLength(1)
? ? ? ? ? ? for (int i = 0; i < a.GetLength(1); i++)
? ? ? ? ? ? {
????????????//int.Parse強制轉(zhuǎn)換成int類型
? ? ? ? ? ? ? ? if (int.Parse(a[1, i]) > max)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max = int.Parse(a[1, i]);
? ? ? ? ? ? ? ? ? ? record = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分?jǐn)?shù)最高的是" + a[0, record] + ",分?jǐn)?shù)是" + a[1, record]);
你說的是用二維數(shù)組做出來嗎?像這樣?
2018-06-20
string[] name = { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" };
? ? ? ? ? ? int[]score = { 89,90,98,56,60,91,93,85};
? ? ? ? ? ? int max = score[0];
? ? ? ? ? ? int record = 0;
? ? ? ? ? ? for (int i = 1; i < score.Length; i++) {
? ? ? ? ? ? ? ? if (score[i]>max) {
? ? ? ? ? ? ? ? ? ? max = score[i];
? ? ? ? ? ? ? ? ? ? record = i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}" + name[record], max);
2018-06-13
那個 親,首先謝謝您啊~~然后我再問下那個,我沒理解錯的話這個應(yīng)該是聲明的兩個數(shù)組的方式·~
親,你會那種聲明 string[,] a = new string[,]{~~~~~};
這種二維的嗎??
2018-06-13
?string[] x = { "吳松", "錢東宇", "伏晨", "陳陸", "周陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" };
? ? ? ? ? ? int[] y = { 89, 90, 98, 56, 60, 91, 93, 85 };
? ? ? ? ? ? int max;
? ? ? ? ? ? max = 0;
? ? ? ? ? ? string name;
? ? ? ? ? ? name = null;
? ? ? ? ? ? for (int i = 0; i < y.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (y[i] > max || max == 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? max = y[i];
? ? ? ? ? ? ? ? ? ? name = x[i];
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}", name, max);
? ? ? ? ? ? Console.ReadLine();
? ? ? ? }
2018-06-13
那個 親,首先謝謝您啊~~然后我再問下那個,我沒理解錯的話這個應(yīng)該是聲明的兩個數(shù)組的方式·~
親,你會那種聲明 string[,] a = new string[,]{~~~~~};
這種二維的嗎??
2018-06-13
?????????? string[] a = new string[] { "吳松", "錢東宇", "伏晨", "陳陸", "周蕊", "林日鵬", "何昆", "關(guān)欣" };
??????????? int[] b = new int[] { 89, 90, 98, 56, 60, 91, 93, 85 };
??????????? int max = 0;
??????????? string name = null;
??????????? for (int i = 0; i < b.Length; i++)
??????????? {
??????????????? if (b[i] > max)
??????????????? {
??????????????????? max = b[i];
??????????????????? name = a[i];
??????????????? }
??????????? }
??????????? Console.Write("分?jǐn)?shù)最高的是{0},分?jǐn)?shù)是{1}", name, max);
2018-06-13
定義一個string數(shù)組存放姓名,一個int數(shù)組存放成績,然后定義一個最大值max,用for循環(huán)嵌套if比較大小把最大值賦給max,并把最大值的索引給姓名數(shù)組。