c#单词个数,加¥,最长单词,平均值

在这里插入图片描述

 static int count(string sentence)
        {
            int count = 0;
            string[] words = new string[100];
            words = sentence.Split(' ');
            for (int i = 0; i < words.Length; i++)
            {
                if (words[i] != "")
                    count++;
            }
            return count;
        }
            string sent = Console.ReadLine(); ;
            Console.WriteLine("{0}里面共有{1}个单词", sent, count(sent));

在这里插入图片描述

在这里插入图片描述

public static string AddDollar(string sentence)
        {
            string st = string.Empty;
            for (int i = 0; i < sentence.Length; i++)
            {
                if (char.IsLetter(sentence[i]))
                {
                    st += sentence[i] + "$";
                }
                else
                {
                    st += sentence[i];
                }
            }
            return st;
        }
            string st = Console.ReadLine();
            Console.WriteLine("加¥后结果为{0}", AddDollar(st));

在这里插入图片描述

找最长单词

static string getLongWord(string sentense)
        {
            string word = "";
            string[] words = new string[100];
            words = sentense.Split(' ');
            for (int i = 0; i < words.Length; i++)
            {

                if (word.Length < words[i].Length)
                {
                    word = words[i];
                }
            }
            return word;
        }
  string st = Console.ReadLine();
  Console.WriteLine("最长的单词是:{0}", getLongWord(st));

在这里插入图片描述
在这里插入图片描述

 public static void getMaxMinAverSum(out int max, out int min, out double aver, out int sum)
        {
            int[] nums = new int[10];
            max = 0;
            min = 50;
            sum = 0;
            Random rnd = new Random();
            for (int i = 0; i < nums.Length; i++)
            {
                nums[i] = rnd.Next(20, 51);
                if (max < nums[i])
                    max = nums[i];
                if (min > nums[i])
                    min = nums[i];
                sum += nums[i];
                Console.Write("{0},", nums[i]);
            }
            aver = (double)sum / nums.Length;
        }
            int max, min, sum;
            double aver;
            getMaxMinAverSum(out max, out min, out aver, out sum);
            Console.WriteLine("最大值{0},最小值{1},平均值{2},和{3}", max, min, aver, sum);

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值