Write a C# Sharp program to check whether a given string starts with "F" or ends with "B". If the string starts with "F" return "Fizz" and return "Buzz" if it ends with "B" If the string starts with "F" and ends with "B" return "FizzBuzz". In other cases return the original string


Write a C# Sharp program to check whether a given string starts with "F" or ends with "B". If the string starts with "F" return "Fizz" and return "Buzz" if it ends with "B" If the string starts with "F" and ends with "B" return "FizzBuzz". In other cases return the original string

If the string starts with "F" return "Fizz" and return "Buzz" if it ends with "B" If the string starts with "F" and ends with "B" return "FizzBuzz".

In other cases return the original string.

الأجوبة

ابحث عن مسائل برمجة سي شارب | c# programming بالانجليزي

using System;
using System.Linq;
namespace exercises
{
   class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(test("FizzBuzz"));
            Console.WriteLine(test("Fizz"));
            Console.WriteLine(test("Buzz"));
            Console.WriteLine(test("Founder"));
            Console.ReadLine();
        }
       public static string test(string str)
        {
            if (str.StartsWith("F") && str.EndsWith("B"))
            {
                return "FizzBuzz";
            }
            else if (str.StartsWith("F"))
            {
                return "Fizz";
            }
            else if (str.EndsWith("B"))
            {
                return "Buzz";
            }
            else
            {
                return str;
            }
        }
    }
}

محتاج مساعدة؟ تواصل مع مدرس اونلاين الان!