We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Wednesday, June 10, 2015

Write a program enter the string and count each character and total characters.


    class Program 
    {

        static void Main(string[] args) 
        {

            string str = "Apple is a nice fruit";

            Console.WriteLine("Total character: {0}", str.Count());

            while (str.Length > 0) 
            {

                Console.Write(str[0] + ": "); 
                int count = 0;
                {
                for (int j = 0; j < str.Length; j++)

                    if (str[0] == str[j]) 
                    {

                        count++;

                    }
                }


                Console.WriteLine(count);

                str = str.Replace(str[0].ToString(), string.Empty);

            }

            Console.ReadLine();


        }

    } 

}

No comments: