zoukankan      html  css  js  c++  java
  • 函数

    把经常用的程序写成函数,直接调用,可以减少编写程序的工作量。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            public static bool zhishu(int shu)
            {
                int c = 0;
                for (int i = 1; i <= shu; i++)
                {
                    if (shu % i == 0)
                    {
                        c++;
                    }
    
                }
                if (c == 2)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public void bzz(string s, int t, int g)
            {
                if (s == "")
                {
                    double n = t - g + 100;
                    if (n >= -3 && n <= 3)
                    {
                        Console.WriteLine("标准");
                    }
                    else if (n > 3)
                    {
                        Console.WriteLine("偏胖");
                    }
                    else
                    {
                        Console.WriteLine("偏瘦");
                    }
                }
                else if (s == "")
                {
                    double n = t - g + 110;
                    if (n >= -3 && n <= 3)
                    {
                        Console.WriteLine("标准");
                    }
                    else if (n > 3)
                    {
                        Console.WriteLine("偏胖");
                    }
                    else
                    {
                        Console.WriteLine("偏瘦");
                    }
                }
                else
                {
                    Console.WriteLine("输入有误");
                }
            }
            
    
                           
            static void Main(string[] args)
            {
                Console.WriteLine("请输入一个数");
                int b = int.Parse(Console.ReadLine());
                bool a = Program.zhishu(b);
                if (a) 
                {
                    Console.WriteLine("是质数");
                }
                else {
                    Console.WriteLine("不是质数");
                }
                Console.WriteLine("请输入性别");
                string c = Console.ReadLine();
                Console.WriteLine("请输入体重");
                int d = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入身高");
                int e = int.Parse(Console.ReadLine());
                Program p = new Program();
                p.bzz(c, d, e);
                
                Console.ReadLine();
            }
        }
    }

    质数  身高体重标准

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication7
    {
        class Program
        {
            public static int[] paixu (int []arr)//定义数组,冒泡排序
            {
                for (int i = 0; i <= arr.Length; i++)
                {
                    for (int j = i; j <= arr.Length - 1; j++)
                    {
                        if (arr[i] < arr[j])
                        {
                            int zhong = 0;
                            zhong = arr[i];
                            arr[i] = arr[j];
                            arr[j] = zhong;
                        }
                    }
    
                }
                for (int i = 0; i < arr.Length; i++)
                {
                    Console.Write(arr[i]+" ");
                }
                return arr;//排好之后输出
            }
            static void Main(string[] args)
            {
                Console.WriteLine("请输入人数");//输入人数
                int renshu = int.Parse(Console.ReadLine());
                int[] arr = new int[renshu];
    
                for (int h = 1; h <= renshu; h++)
                {
                    Console.WriteLine("请输入第{0}个人的成绩", h);//输入成绩
                    arr[h - 1] = int.Parse(Console.ReadLine());
                   
                }
    
    
                 Program.paixu(arr);//调用函数,输出
                
                
                Console.ReadLine();
            }
        }
    }

    冒泡排序

  • 相关阅读:
    dubbo+zookeeper注册服务报错问题:No service registed on zookeeper
    悲观锁和乐观锁的区别,它们是怎么实现
    cookie和session的区别,分布式环境怎么保存用户状态
    深入理解Java接口和抽象类
    Java中堆内存和栈内存详解
    Java基础梳理(一)
    Spring的@Transactional注解详细用法
    SpringBoot学习笔记(一)基础
    项目实体类使用@Data注解,但是项目业务类中使用getA(),setA()方法报错,eclipse中配置lombok
    有依赖的背包问题-购物单
  • 原文地址:https://www.cnblogs.com/jskbk/p/5359389.html
Copyright © 2011-2022 走看看