開発環境
- Microsoft Windows 7 Home Premium (OS)
- Microsoft Visual C# 2010 Express Edition (IDE)
- 言語: C#
『初めてのC# 第2版』(Jesse Liberty+Brian MacDonald著、日向俊二訳、オライリー・ジャパン、2006年、ISBN978-487311-294-7)の 第10章(配列)10.9(練習問題)練習10-2を解いてみる。
練習10-2.
コード
using System;
class Tester
{
public void Run()
{
try
{
int[] ary = new int[10];
Console.WriteLine("整数を10個入力");
for (int i = 0; i < ary.Length; i++)
{
ary[i] = Convert.ToInt16(Console.ReadLine());
}
Array.Sort(ary);
Array.Reverse(ary);
Console.WriteLine("降順");
foreach (int item in ary)
{
Console.Write("{0} ", item);
}
Console.WriteLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
static void Main()
{
Tester t = new Tester();
t.Run();
}
}
入出力結果(Console Window)
整数を10個入力 1 0 2 9 3 8 4 7 5 6 降順 9 8 7 6 5 4 3 2 1 0 続行するには何かキーを押してください . . .
0 コメント:
コメントを投稿