Console.WriteLine("請輸入10個數(shù)字");
int a = 0; //記錄數(shù)字1的個數(shù)
int b = 0; //記錄數(shù)字2的個數(shù)
int c = 0; // 記錄數(shù)字3的個數(shù)
int d = 0; // 記錄不合法的數(shù)字的個數(shù)
int [] shuzhu = new int [10];//儲存用戶輸入的數(shù)字
try
{
for (int i = 0; i <shuzhu.Length; i++)
{
Console.WriteLine("請輸入第{0}個數(shù)字",i+1);
shuzhu[i] = Convert.ToInt32(Console.ReadLine());
switch (shuzhu[i])
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
default:
d++;
break;
}
}
Console.WriteLine("數(shù)字1的個數(shù)是{0}",a);
Console.WriteLine("數(shù)字2的個數(shù)是{0}", b);
Console.WriteLine("數(shù)字3的個數(shù)是{0}", c);
Console.WriteLine("數(shù)字不合法的個數(shù)是{0}", d);
}
catch
{
Console.WriteLine("輸入錯誤");
}
Console.ReadKey();