C#基础练习题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 练习
{
    class Program
    {

        #region 利用方法来说明方法的重载
        static void M()
        {
            
        }
        static void M(int A)
        {

        }
        static void M(string A)
        {

        }
        static void M(int A,int B)
        {

        }
        static void M(int A,string B)
        {

        }
        static void M(string A,int B)
        {

        }
        #endregion
        static void Main(string[] args)
        {
            #region 求一个数组的平均值{1,3,5,7,90,2,4,6,8,10} 有小数则显示小数点后两位
            //int[] arrInt = { 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 ,1,3,5};
            //double avg = GetAvg(arrInt);
            //Console.WriteLine("平均值是:{0}",avg);
            //Console.ReadLine();
            #endregion

            #region 通过冒泡排序对整数数组{1,3,5,7,90,2,4,6,8,10}实现升序排序
            //int[] arrInt={ 1,3,5,7,90,2,4,6,8,10 };
            //for (int i = 0; i < arrInt.Length; i++)
            //{
            //    for (int j = arrInt.Length-1; j > i; j--)
            //    {
            //        if (arrInt[j] < arrInt[j - 1])
            //        {
            //            int num = arrInt[j];
            //            arrInt[j] = arrInt[j - 1];
            //            arrInt[j - 1] = num;
            //        }

            //    }
            //}
            //for (int n = 0; n < arrInt.Length; n++)
            //{
            //    Console.WriteLine(arrInt[n]);
            //}
            //Console.ReadLine();
            #endregion
            #region 有如下字符串:【"患者:"大夫,我咳嗽得很重。" 大夫:"你多大年记?" 患者:"七十五岁。" 大夫:"二十岁咳嗽吗"患者:"不咳嗽。" 大夫:"四十岁时咳嗽吗?" 患者:"也不咳嗽。" 大夫:"那现在不咳嗽,还要等到什么时咳嗽?""】。需求:①请统计出该字符中"咳嗽"二字的出现次数,以及每次"咳嗽"出现的索引位置。②扩展(*):统计出每个字符的出现次数(后面)
            //string msg= "患者:大夫,我咳嗽得很重。 大夫:你多大年记? 患者:七十五岁。 大夫: 二十岁咳嗽吗 患者: 不咳嗽。 大夫:四十岁时咳嗽吗? 患者:也不咳嗽。大夫:那现在不咳嗽,还要等到什么时咳嗽?";
            Indexof()  返回指定字符第一次出现的索引位置
            LastIndexOf()  返回指定字符最后一次出现的索引位置

            记录咳嗽出现的次数
            //int count = 0;
            出现的索引位置
            //int index = 0;
            //while ((index=msg.IndexOf("咳嗽",index))!=-1)//条件就是查找后返回不是-1
            //{
            //    c
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值