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
C#基础练习题
最新推荐文章于 2025-04-07 15:52:16 发布