• 刚学了函数,关于有无参数和返回值的四种情况的查找数字的代码


    static void Main(string[] args)
    {
    ////无参无反
    //cz();

    ////无参有返
    //bool bbb = chaz();
    //if (bbb == true)
    //{
    // Console.WriteLine("找到啦");
    //}
    //else
    //{
    // Console.WriteLine("没找到");
    //}


    ////有参无返
    //Console.WriteLine("请输入一个数");
    //int d = Convert.ToInt32(Console.ReadLine());
    //chazhao(d);


    ////有参有返
    //Console.WriteLine("请输入一个数");
    //int d = Convert.ToInt32(Console.ReadLine());
    //bool b = chazhaoaaa(d);
    //if (b == true)
    //{
    // Console.WriteLine("找到啦");
    //}
    //else
    //{
    // Console.WriteLine("没找到");
    //}

    }
    //有参有返
    static bool chazhaoaaa(int d)
    {

    int[] a = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    bool b = false;
    for (int i = 0; i < a.Length; i++)
    {
    if (a[i] == d)
    {
    b = true;
    break;
    }


    }
    return b;

    }

    //有参无返
    static void chazhao(int d)
    {

    int[] a = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    bool b = false;
    for (int i = 0; i < a.Length; i++)
    {
    if (a[i] == d)
    {
    b = true;
    break;
    }


    }
    if (b == true)
    {
    Console.WriteLine("找到啦");
    }
    else
    {
    Console.WriteLine("没找到");
    }

    }


    //查找 无参有返
    static bool chaz()
    {
    bool b = false;
    Console.WriteLine("请输入一个数");
    int d = Convert.ToInt32(Console.ReadLine());
    int[] a = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };

    for (int i = 0; i < a.Length; i++)
    {
    if (a[i] == d)
    {
    b = true;
    break;
    }


    }

    return b;
    }


    //查找 无参无反
    static void cz()
    {
    Console.WriteLine("请输入一个数");
    int d=Convert.ToInt32(Console.ReadLine());
    int[] a = new int[10] { 1,2,3,4,5,6,7,8,9,0};
    bool b=false;
    for (int i = 0; i < a.Length; i++)
    {
    if (a[i]==d)
    {
    b = true;
    break;
    }


    }
    if (b == true)
    {
    Console.WriteLine("找到啦");
    }
    else
    {
    Console.WriteLine("没找到");
    }

  • 相关阅读:
    牛牛与LCM(最小公约数)
    小明的挖矿之旅_牛客网(思维题)
    2019/4/20周赛 F题 CodeForces
    哥德巴赫猜想_2019/7/11_牛客网
    智障操作-wireless AC 9462
    codeforces762A
    2019中山大学程序设计竞赛(重现赛)斐波那契/
    Java自学笔记(10):【面向对象 】 类和对象、构造方法、this关键字
    Java自学笔记(9):方法
    Java自学笔记(8):多维数组
  • 原文地址:https://www.cnblogs.com/zzc134680/p/5429980.html
Copyright © 2020-2023  润新知