• 7.31


    函数 有四种格式 

    格式1:无参无返
    <summary>
    累加求和,不需要参数,没有返回值
    </summary>
    public void LeiJia()
    {
    累加求和
    Console.Write("请输入一个正整数:");
    int a = int.Parse(Console.ReadLine());
    int sum = 0;
    for (int i = 1; i <= a; i++)
    {
    sum += i;
    }
    Console.WriteLine(sum);
    Console.ReadLine();
    }

    格式2:无参有返
    public int LeiJia1()
    {
    //累加求和
    Console.Write("请输入一个正整数:");
    int a = int.Parse(Console.ReadLine());
    int sum = 0;
    for (int i = 1; i <= a; i++)
    {
    sum += i;
    }

    return sum;
    }

    格式3:有参有返
    public int LeiJia2(int a)
    {
    //累加求和
    int sum = 0;
    for (int i = 1; i <= a; i++)
    {
    sum += i;
    }
    return sum;
    }

    格式4:有参无返
    public void LeiJia3(int a)
    {
    //累加求和
    int sum = 0;
    for (int i = 1; i <= a; i++)
    {
    sum += i;
    }
    Console.WriteLine(sum);
    Console.ReadLine();
    }

    有参数表示在函数体中不需要再去接收
    有返回值表示,我在下文中还需要使用这个结果
    在调用函数的时候需要定义一个相同数据类型的变量接收


    函数,比较大小返回大的
    public double Max(double a, double b)
    {
    if (a > b)
    {
    return a;
    }
    else//a<=b
    {
    return b;
    }
    }

    函数可以嵌套使用,但是函数不可以嵌套写

    public void you()//邮箱,无参无返
    {
    Console.Write("请输入邮箱:");
    string yx = Console.ReadLine();
    if (yx.Contains("@"))
    {
    int a = yx.IndexOf("@");
    int b = yx.LastIndexOf("@");
    if (a == b)
    {
    if (!yx.StartsWith("@"))
    {
    string c = yx.Substring(a);
    if (c.Contains("."))
    {
    string d = yx.Substring(a - 1, 1);
    string e = yx.Substring(a, 1);
    if (d != "." && e != ".")
    {
    if (!yx.EndsWith("."))
    {
    Console.WriteLine("您输入的邮箱格式正确");
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }

    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    Console.ReadLine();
    }

    public string you2() //无参有返
    {
    Console.Write("请输入邮箱:");
    string yx = Console.ReadLine();
    if (yx.Contains("@"))
    {
    int a = yx.IndexOf("@");
    int b = yx.LastIndexOf("@");
    if (a == b)
    {
    if (!yx.StartsWith("@"))
    {
    string c = yx.Substring(a);
    if (c.Contains("."))
    {
    string d = yx.Substring(a - 1, 1);
    string e = yx.Substring(a, 1);
    if (d != "." && e != ".")
    {
    if (!yx.EndsWith("."))
    {
    Console.WriteLine("您输入的邮箱格式正确");
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }

    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }

    return yx;
    }

    //有参有返
    public string you3(string yx)
    {
    if (yx.Contains("@"))
    {
    int a = yx.IndexOf("@");
    int b = yx.LastIndexOf("@");
    if (a == b)
    {
    if (!yx.StartsWith("@"))
    {
    string c = yx.Substring(a);
    if (c.Contains("."))
    {
    string d = yx.Substring(a - 1, 1);
    string e = yx.Substring(a, 1);
    if (d != "." && e != ".")
    {
    if (!yx.EndsWith("."))
    {
    Console.WriteLine("您输入的邮箱格式正确");
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }

    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    return yx;
    }

    //有参无返


    public void you4(string yx)
    {
    if (yx.Contains("@"))
    {
    int a = yx.IndexOf("@");
    int b = yx.LastIndexOf("@");
    if (a == b)
    {
    if (!yx.StartsWith("@"))
    {
    string c = yx.Substring(a);
    if (c.Contains("."))
    {
    string d = yx.Substring(a - 1, 1);
    string e = yx.Substring(a, 1);
    if (d != "." && e != ".")
    {
    if (!yx.EndsWith("."))
    {
    Console.WriteLine("您输入的邮箱格式正确");
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }

    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    }
    else
    {
    Console.WriteLine("邮箱输入错误");
    }
    Console.ReadLine();
    }

  • 相关阅读:
    P1631-序列合并
    P1484-种树
    17.树的子结构(python)
    16.合并两个排序的链表(python)
    反转链表
    链表中倒数第k个节点(python)
    调整数组顺序使奇数位于偶数前面(python)
    Spark--wordcount(词频降序)
    数值的整数次方
    二进制中1的个数(python)
  • 原文地址:https://www.cnblogs.com/power8023/p/5726223.html
Copyright © 2020-2023  润新知