zoukankan      html  css  js  c++  java
  • 函数的主要内容

    namespace 函数
    {   //函数的作用:提高代码的重用性,一块封闭的代码块。
        //语法结构:返回值(当执行完函数之后,返回的结果的数据类型),函数名,输入参数,输出参数,函数体。
        //一:无返回值,无参数的函数
        /* public void dayin()  //只是调用,不需要返回值
            {
                Console.WriteLine("hello,world");
            }
         */
        /*public void jiafa()
            {
                int a = Convert.ToInt32(Console.ReadLine());
                int b = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine(a+b);
            }
       */

        //二:有返回值,无参数的
        //三:有返回值,有输入参数的
           //四:有返回值,有输入输出参数的

            //public int/*返回值*/ qiuhe/*输出函数*/(int n/*输入函数*/)
            //{
            //    int sum = 0; //最终求和结果
            //    for (int i = 0; i <= n; i++)
            //    {
            //        sum = sum + i;
            //    }
            //    return sum;
            //}

            //public void dayin()  //只是调用,不需要返回值
            //{
            //    Console.WriteLine("hello,world");
            //}
            public string caiquan(int a,int b)
            {
            string s="";
            if (a - b == -1 || a - b == 2)
            {
               s= "人赢了";
            }
            else if (a == b)
            {
               s="平局";
            }
            else
            {
                s="电脑赢了";
            }
            return s;
            }

            static void Main(string[] args)
            {
                
                //输入一个数,累加求和
                //Console.WriteLine("请输入一个数:");
                //int shu = Convert.ToInt32(Console.ReadLine());

                //int sum=new Program().qiuhe(shu);
                //Console.WriteLine(sum);

                //new Program().dayin();

                //new Program().jiafa();

                Console.WriteLine("请输入一个数:0-剪刀1-布2-石头");
                int a = Convert.ToInt32(Console.ReadLine());
                Random r = new Random();
                int b = r.Next(3);
                Console.WriteLine("电脑出"+b);
                string jieguo= new Program().caiquan(a,b);
                Console.WriteLine(jieguo);
                Console.ReadLine();
            }
        }
    }

  • 相关阅读:
    apache2+django+virtualenv 服务器部署实战
    从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系
    Causal Corpus 事件因果关系语料统计
    Event StoryLine Corpus 论文阅读
    哈工大计算机网络Week2-网络应用数据交换
    哈工大计算机网络Week3-传输层
    哈工大计算机网络Week1-网络应用
    哈工大计算机网络Week0-概述
    python爬虫入门
    对scanner.close方法的误解以及无法补救的错误
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4420583.html
Copyright © 2011-2022 走看看