当前位置:网站首页>C number of words, plus ¥, longest word, average value

C number of words, plus ¥, longest word, average value

2022-07-07 23:33:00 Bobo in summer

 Insert picture description here

 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} There's something in it {1} Word ", sent, count(sent));

 Insert picture description here

 Insert picture description here

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(" Add ¥ The result is {0}", AddDollar(st));

 Insert picture description here

Find the longest word

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(" The longest word is :{0}", getLongWord(st));

 Insert picture description here
 Insert picture description here

 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(" Maximum {0}, minimum value {1}, Average {2}, and {3}", max, min, aver, sum);

 Insert picture description here

原网站

版权声明
本文为[Bobo in summer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130558212249.html