题目
非法数字
代码
Console.WriteLine("请输入十个数:");
int[] nums=new int [9];
int[] count = new int[4];
for (int i = 0; i < nums.Length; i++)
{
Console.WriteLine("请输入第{0}个数", i + 1);
nums[i]=Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < nums.Length; i++)
{
if (nums[i] == 1)
{
count[0] = count[0] + 1;
continue;
}
if (nums[i] == 2)
{
count[1] = count[1] + 1;
continue;
}
if (nums[i] == 3)
{
count[2] = count[2] + 1;
continue;
}
else
{
count[3] = count[3] + 1;
}
}
Console.WriteLine("数字1的个数为{0}:",count[0]);
Console.WriteLine("数字2的个数为{0}:",count[1]);
Console.WriteLine("数字3的个数为{0}:",count[2]);
Console.WriteLine("非法数字的个数为{0}:",count[3]);
Console.ReadKey();
网友评论