how to print palindrome words in given string ??
input : madam arora teaches malayalam
o/p: madam, arora,malayalam.
i tried my own but not working pls help
how to print palindrome words in given string ??
input : madam arora teaches malayalam
o/p: madam, arora,malayalam.
i tried my own but not working pls help
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lalit HolkarRank #9,026 · 212 reputationPosted Oct 2, 2022, 7:28 PM EDT
public void Pallon() { string oldval = "madam arora teaches malayalam"; Console.WriteLine(oldval); Console.WriteLine(); string[] oldArr = oldval.Split(' '); List lstnew = new List(); for (int i = 0; i = 0; j--) { newstr = newstr + oldstr[j]; } if (oldArr[i] == newstr) { lstnew.Add(oldArr[i]); } } //for Print The Output for (int i = 0; i < lstnew.Count; i++) { Console.Write(lstnew[i] + ' '); } }Vishal JoshiRank #377 · 6.7K reputationPosted Oct 3, 2022, 1:27 AM EDT
Hello,
Please check the below code for the solution.
static void Main(string[] args) { Console.WriteLine("Please enter text:"); string Input = Console.ReadLine(); Console.WriteLine(); string[] wordsArr = Input.Split(' '); List lstPalindromeWords = new List(); for (int i = 0; i = 0; j--) { newStr = newStr + wordStr[j]; } if (wordsArr[i].Trim().ToLower() == newStr.Trim().ToLower()) { lstPalindromeWords.Add(wordsArr[i]); } } Console.WriteLine(); Console.WriteLine("Output:"); //Output for (int i = 0; i < lstPalindromeWords.Count; i++) { if (i < lstPalindromeWords.Count - 1) Console.Write(lstPalindromeWords[i] + ", "); else Console.Write(lstPalindromeWords[i] + "."); } Console.ReadLine(); }Jaya PrakashRank #1,293 · 1.3K reputationPosted Oct 3, 2022, 2:05 AM EDT
Thank you both for ur help