Visual StudioC#窗体应用程序,输入不定长度求平均值,最大值,最小值

程序代码:

using System;
/*编写Test类,包含average方法、Max方法、Min方法,实现求数组中所有元素的平均值、最大值、最小值,在Main中调用方法并显示出来*/
namespace 求平均值_最大值_最小值
{   class Test {
       public void Average(params int[] a)
        {      //params 表示不定长参数.
            double sum = 0, average = 0;
            for (int i=0; i max) max = a[i];
            }
            Console.WriteLine("最大值为:" + max);

        }
        public void Min(params int[] a) {
            int min = a[0];
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] < min) min = a[i];
            }
            Console.WriteLine("最小值为:" + min);
        }
      
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一组整数中间用逗号隔开,并求出平均值、最大值、最小值");
           
            string str = Console.ReadLine();
            string[] s = str.Split(',');
            int[] b = new int[s.Length];//分配大小为int[s.length]的空间
            for (int i =0;i

运行截图:

Visual StudioC#窗体应用程序,输入不定长度求平均值,最大值,最小值_第1张图片

你可能感兴趣的:(Visual StudioC#窗体应用程序,输入不定长度求平均值,最大值,最小值)