C# Sharp Exercises: Reverse all the words of a given string which have even length
C# Sharp String: Exercise-55 with Solution
Write a C# Sharp program reverse all the words of a given string which have even length.
Sample Solution:-
C# Sharp Code:
using System;
using System.Linq;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
string str1 = "C# Exercises";
Console.WriteLine("Original string: " + str1);
Console.WriteLine("\nReverse all the words of the said string which have even length.:\n" + test(str1));
str1 = "C# is used to develop web apps , desktop apps , mobile apps , games and much more.";
Console.WriteLine("\nOriginal string: " + str1);
Console.WriteLine("\nReverse all the words of the said string which have even length.:\n" + test(str1));
}
public static string test(string text)
{
return string.Join(" ", text.Split(' ').Select(str => str.Length % 2 != 0 ? str : new String(str.Reverse().ToArray())));
}
}
}
Sample Output:
Original string: C# Exercises Reverse all the words of the said string which have even length.: #C Exercises Original string: C# is used to develop web apps , desktop apps , mobile apps , games and much more. Reverse all the words of the said string which have even length.: #C si desu ot develop web sppa , desktop sppa , elibom sppa , games and hcum more.
Flowchart :
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to alternate the case of each letter in a given string and the first letter of the said string must be uppercase.
Next: Write a C# Sharp program to find the longest common ending between two given strings.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework