Random a = new Random();
string[] s = {"+","-","*","/"};
List<int> resultList = new List<int>();
for(int j =0;j<10;j++)
{
int n1= a.Next();// 第一个数
int n2 = a.Next();//第二个数
string sn = s[a.Next(4)];//运算符
int result = 0; //这是答案
switch(sn)
{
case "+":
result = n1+n2;
break;
case "-":
result = n1-n2;
break;
case "*":
result = n1*n2;
break;
case "/":
result = n1/n2;
break;
}
Console.WriteLine(n1.ToString() + sn + n2.ToString()+"=" );
resultList.Add(result);
}
Console.WriteLine("输入答案,每个答案用逗号分割“,” 英文逗号");
string str = Console.ReadLine();
string[] arr= str.Split(',');
for(int i = 0;i<resultList.Count;i++;)
{
if(Convert.ToInt32(arr)==resultList)
{
Console.WriteLine("第"+i+"题正确");
}else
{
Console.WriteLine("第"+i+"题错误");
}
}
|