首先把英文句子按照空格分割成单词,放到数组里比较长短。

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("输入一句英文句子");
            string str = Console.ReadLine();//获取控制台输入的句子
            string[] arr = str.Split(' ');//以空格分割放进数组
            int num = 0;
            //使用foreach循环,注意:foreach循环效率最高
            foreach (string item in arr)
            {
                if (item.Length>num) 
                {
                    num = item.Length;
                }
            }
            Console.WriteLine("其中最长的单词是");
            foreach (string item in arr)
            {
                if (item.Length==num)
                {
                    Console.WriteLine(item);
                }
            }
            Console.ReadLine();
        }
    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-05-11
  • 2022-12-23
猜你喜欢
  • 2021-04-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案