Risipa de key_press | Programare

Programare .Net | Tehnici de programare | Tutoriale | Lectii si exemple

Risipa de key_press | Programare - Programare .Net | Tehnici de programare | Tutoriale | Lectii si exemple

Cautarea unui caracter intr-un sir

Sa se afiseze de cate ori apare in sir un caracter citit de la tastatura.

using System;
/*
 Sa se afiseze de cate ori apare in sir un caracter citit de la tastatura
 */

namespace S2
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;

            Console.WriteLine("Introduceti sirul:");
            char[] myString = Console.ReadLine().ToCharArray();

            Console.WriteLine("Introduceti caracterul cautat:");
            char charToFind = Convert.ToChar(Console.Read());

            for(int i = 0; i < myString.Length; i++)
            {
                if (myString[i] == charToFind)
                    count++;
            }

            Console.WriteLine("Caracterul {0} a aparut de {1} ori", charToFind, count);
            
            Console.ReadLine();
        }
    }
}
Category: Uncategorized

Your email address will not be published. Required fields are marked *

*