If I have String "This radar is good" and I need to find palindrome word out of the String without using String function | Selenium C# Forum
S
Shalvi Posted on 09/10/2022

I tried writing below logic but finding error at comp = strarr[j];.

Details of error:

Array out of bound

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
public class Palindrome1
{
public static void Main(String[] args)
{
//String str = "This radar is good";
String[] strarr = new String[4]; // { "This", "radar", "is", "good" };
strarr[0] = "This";
strarr[1] = "radar";
strarr[2] = "is";
strarr[3] = "good";
String comp;

for (int i = 0; i < strarr.Length; i++)
{
for (int j = ((strarr[i].Length) - 1); j >= 0; j--)
{
comp = strarr[j];
Console.WriteLine(comp);
}
}
Console.WriteLine(strarr[0]);
Console.ReadKey();
}
}
}