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();
            }
        }
    }

  • 相关阅读:
    HTML5触摸屏touch事件使用介绍1
    hdu 1408 acdearm &quot;Money, Money, Money&quot;
    基于QTP的自己主动化測试框架介绍
    ExpandListView onChildClickListener 失效
    hdu1227 Fast Food
    Linux C高级编程——文件操作之系统调用
    nodejs之路-[0]安装及简易配置
    动态加入改动删除html表格内容
    socket网络编程基础小记
    LeetCode OJ Minimum Depth of Binary Tree 递归求解
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4420583.html
Copyright © 2011-2022 走看看