標題:
C# 7 307 反轉陣列
[打印本頁]
作者:
may
時間:
2024-1-8 22:18
標題:
C# 7 307 反轉陣列
TQC+ 物件導向程式語言
最新一次更新時間:2024-01-05 14:52:39
1. 題目說明:
請新增一個主控台應用程式,加入C:\ANS.CSF\CS03資料夾中的CSD03.cs進行編寫。依下列題意進行作答:建立一個陣列,予以反轉後輸出,使輸出值符合題意要求。檔案名稱請另存新檔為CSA03.cs,儲存於C:\ANS.CSF\CS03資料夾,再進行評分。
2. 設計說明:
專案中已提供一個名為compute()的方法,接收Main()傳遞的一個陣列。請在Main()中宣告一個陣列,讓使用者輸入資料,直到輸入999結束,將輸入的資料存入此宣告的陣列,再將此陣列傳遞給compute()方法。
在compute()方法中進行陣列反轉,輸出陣列反轉前反轉後的內容。
3. 輸入輸出:
輸入說明
資料內容,直到輸入999結束
輸出說明
反轉前before、反轉後after的陣列內容
範例輸入1
901
293
John
999
範例輸出1
before:901 293 John
after:John 293 901
4. 評分項目:
(1) 符合設計說明輸出正確格式 配分 20
作者:
may
時間:
2024-1-9 09:26
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSA03
{
class CSA03
{
static void Main(string[] args)
{
try
{
List<string> lst = new List<string>();
string str = "";
while (true)
{
str = Console.ReadLine();
if (str != "999")
{
lst.Add(str);
}
else
{
break;
}
}
compute(lst);
}
catch
{
Console.Write("error");
}
Console.ReadKey();
}
// ==================================================
// Please write your code in the specified Method
// Do NOT change the method name, type of parameter
// ==================================================
static void compute(List<string> lst)
{
Console.WriteLine("before:" + String.Join(" ", lst));
lst.Reverse();
Console.WriteLine("after:" + String.Join(" ", lst));
}
}
}
複製代碼
作者:
李泳霖
時間:
2024-2-1 22:26
using ConsoleApp1;
using System;//程式庫呼叫
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
using ABC.qq;
class Program//負責一部分工作的人
{
static void Main()
{
try
{
List<string> lst = new List<string>();
string str = "";
while (true)
{
str = Console.ReadLine();
if (str != "999")
{
lst.Add(str);
}
else
{
break;
}
}
compute(lst);
} catch
{
Console.WriteLine("error");
}
Console.ReadKey();
}
static void compute(List<string> lst)
{
Console.WriteLine("before:"+String.Join(" ",lst));
lst.Reverse();
Console.WriteLine("afer:" + String.Join(" ", lst));
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2