- class Program
- {
- static int ReadInt()
- {
- do
- {
- try
- {
- int a = Convert.ToInt32(Console.ReadLine());
- return a;
- }
- catch
- {
- Console.WriteLine("您输入的字符串格式有误,请重新输入");
- }
- } while (true);
- }
- static void Main(string[] args)
- {
- int[] num = new int[10];
- //给每个元素赋值
- for (int i = 0; i < num.Length; i++)
- {
- Console.WriteLine("第{0}个同学成绩为:", i + 1);
- num[i] = ReadInt();
- }
- //清屏
- Console.Clear();
- //求最大值,最小值
- Array.Sort(num);//调用数组的方法进行排序,此处有for循环求最大值,最小值也可用冒泡排序法
- Console.WriteLine("最大值为{0}:,最小值为{1}", num[num.Length-1],num[0]);
- Console.ReadKey();
- }
- }
复制代码 |