//定义一个方法,要求用户输入一个数,如果输入的是数则返回主掉方法,如果输入的不是数则提示用户输入错误并要求重新输入,直到输入的为数为止;
public static int MyTest()
{
int number;
do
{
try
{
number = Int32.Parse(Console.ReadLine());
return number;
}
catch
{
Console.Write("您的输入有误,请重新输入:");
}
} while (true);
}
////给数组赋值;
public static int[] InputArray(int count)
{
int[] array = new int[count];
int number = 0;
for (number = 0; number < array.Length; number++)
{
Console.WriteLine("请输入第{0}个数:", number + 1);
array[number] = MyTest();
}
return array;
}
//求数组的和;
public static int Sum(int[] array)
{
int number = 0, sum = 0;
for (number = 0; number < array.Length; number++)
{
sum += array[number];