zoukankan      html  css  js  c++  java
  • 例题:函数输出参数。理解函数的作用,函数是一个相对独立的代码块

    class Program
        {
            public  int[] shuchucanshu(int[] shu,out int a,out int b) //基本格式,定义一个int数组
            {
                for (int i = 0; i < shu.Length ; i++) //冒泡排序
                {
                    for (int j = i; j < shu.Length -1; j++)
                    {
                        if (shu[i]<shu[j+1])
                        {
                            int zhong = 0;
                            zhong = shu[i];
                            shu[i] = shu[j + 1];
                            shu[j + 1] = zhong;
                        }
                    }
                }
                a = shu[0]; //最大值
                b = shu[shu.Length - 1];//最小值。排序已经拍好,[shu.Length - 1]是最小数的下标
              
                return shu;
            }
            static void Main(string[] args)
            { 
                int a,b; //声明,与函数里的a,b没有任何关系,函数是独立的代码块
                int[] shu=new int[5]{1,3,5,9,6};
                new Program ().shuchucanshu (shu,out a,out b); //调用函数
                for (int i = 0; i < shu.Length ; i++)
                {
                    Console.WriteLine(shu[i]);
                }
                Console.WriteLine("最大值是"+a+",最小值是"+b);
                Console.ReadLine();
            }

  • 相关阅读:
    LeetCode: Longest Valid Parentheses 解题报告
    LeetCode: Generate Parentheses 解题报告
    Leetcode: LRU Cache 解题报告
    LeetCode: Maximal Rectangle 解题报告
    LeetCode: Min Stack 解题报告
    LeetCode: Restore IP Addresses 解题报告
    LeetCode: Longest Common Prefix 解题报告
    LeetCode: Regular Expression Matching 解题报告
    Python——rrdtool模块的安装
    python-xlsxwriter模块绘制表格
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4428849.html
Copyright © 2011-2022 走看看