• C#练习题18和19和20和21


    第18题:
    从一个整数数组中取出最大的整数、最小的整数、总和、平均数

    using System;
    
    namespace 练习题18
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8 };
                int max = 0, min = 0, sum = 0;
                double average = 0.0;
                for(int i=0;i<nums.Length;i++)
                {
                    if (nums[i] >= max)
                        max = nums[i];
                    else
                        min = nums[i];
                    sum += nums[i];
                    average = ((double)sum) / nums.Length;
                }
                Console.WriteLine("该数组中最大的整数是:{0},最小整数是:{1},总和是:{2},平均数是:{3}",max,min,sum,average);
                Console.ReadKey();
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    在这里插入图片描述

    第19题:
    数组里面都是人的名字,分割成:例如:老杨|老苏|老邹…“(老杨,老苏,老邹,老虎,老牛,老蒋,老王,老马)

    using System;
    
    namespace 练习题19
    {
        class Program
        {
            static void Main(string[] args)
            {
                string[] names = { "老杨", "老苏", "老邹", "老虎", "老牛", "老蒋", "老王", "老马" }; 
                string str = null;
                for(int i=0;i<names.Length-1;i++)
                {
                    str += names[i] + "|";
                }
                str = str + names[names.Length - 1];
                Console.WriteLine(str);
                Console.ReadKey();
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    在这里插入图片描述

    第20题:

    using System;
    
    namespace 练习题20
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] a = { -9, -2, 0, 1, 2, 4, 3, 9 };
                for (int i = 0; i < a.Length; i++)
                {
                    if (a[i] > 0)
                        a[i] += 1;
                    else if(a[i] < 0)
                        a[i] -= 1;
                    else
                        a[i] = a[i];
                }
                for (int i = 0; i < a.Length; i++)
                {
                    Console.WriteLine(a[i]);
                }
                Console.ReadLine();
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    在这里插入图片描述

    第21题:

    using System;
    
    namespace 练习题21
    {
        class Program
        {
            static void Main(string[] args)
            {
                string[] names = { "我", "是", "好人" };
                string temp = "";
                for(int i=0;i<names.Length/2;i++)
                {
                    temp = names[i];
                    names[i] = names[names.Length - i - 1];
                    names[names.Length - i - 1] = temp;
                }
                for(int i=0;i<names.Length;i++)
                {
                    Console.WriteLine(names[i]);
                }
                Console.ReadKey();
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    在这里插入图片描述

  • 相关阅读:
    【Java-框架-SpringMVC】(01) SpringMVC框架的简单创建与使用,快速上手 - 简易版
    1011 World Cup Betting
    vue父组件向子组件传值的方法
    MacOS Anaconda 安装教程及虚拟环境创建
    java自习室管理系统计算机毕业设计MyBatis+系统+LW文档+源码+调试部署
    南宁师范大学计算机考研资料汇总
    倪师哲学。把智慧和时间都用在学习知识上
    Baichuan2大模型本地部署
    Elasticsearch基础条件查询
    我记不住的那些命令(不断更新中)
  • 原文地址:https://blog.csdn.net/AKK188888881/article/details/126226138