A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C# Sharp program to count the string "aa" in a given string and assume "aaa" contains two "aa"
Q:

Write a C# Sharp program to count the string "aa" in a given string and assume "aaa" contains two "aa"

0

Write a C# Sharp program to count the string "aa" in a given string and assume "aaa" contains two "aa"

Sample Output:

2
2
3

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
namespace exercises
{
   class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(test("bbaaccaag"));
            Console.WriteLine(test("jjkiaaasew"));
            Console.WriteLine(test("JSaaakoiaa"));
            Console.ReadLine();
        }
       
     public static int test(string s)
        {
            int ctr_aa = 0;
            for (int i = 0; i < s.Length - 1; i++)
            {
                if (s.Substring(i, 2) == "aa")
                {
                    ctr_aa++;
                }
            }
            return ctr_aa;
        }
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now