#作业代码
try
{
int[] num = new int[10];//定义数组
int[] count = new int[4];//定义数组
Console.WriteLine("请输入10个数");
for (int i = 0; i < num.Length; i++)
{
Console.Write("请输入第{0}个数:", i + 1);
num[i] = Convert.ToInt32(Console.ReadLine());
//存入数组
switch (num[i])
{
case 1:
count[0] += 1;
break;
case 2:
count[1] += 1;
break;
case 3:
count[2] += 1;
break;
default:
count[3] += 1;
break;
}
}
Console.WriteLine("数字1的个数: {0}", count[0]);
Console.WriteLine("数字2的个数: {0}", count[1]);
Console.WriteLine("数字3的个数: {0}", count[2]);
Console.WriteLine("非法数字的个数: {0}", count[3]);
}
catch
{
Console.WriteLine("你输入的格式有误");
}
Console.ReadKey();
#作业效果: