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 check if a given string contains two similar consecutive letters
Q:

Write a C# Sharp program to check if a given string contains two similar consecutive letters

0

Write a C# Sharp program to check if a given string contains two similar consecutive letters

Sample Output:

Original string: PHP
Test for consecutive similar letters! False
Original string: PHHP
Test for consecutive similar letters! True
Original string: PHPP
Test for consecutive similar letters! True
Original string: PPHP
Test for consecutive similar letters! True

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("Original string: PHP");
            Console.WriteLine("Test for consecutive similar letters! " + test("PHP"));
            Console.WriteLine("Original string: PHHP");
            Console.WriteLine("Test for consecutive similar letters! " + test("PHHP"));
            Console.WriteLine("Original string: PHPP");
            Console.WriteLine("Test for consecutive similar letters! " + test("PHPP"));
            Console.WriteLine("Original string: PPHP");
            Console.WriteLine("Test for consecutive similar letters! " + test("PPHP"));
        }
        public static bool test(string text)
        {
            for (int i = 0; i < text.Length - 1; i++)
            {
                if (text[i] == text[i + 1]) 
                    { 
                      return true; 
                    }
            }
            return false;
        }
    }
}

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