C# Sharp Exercises: Reverse the words of a sentence
C# Sharp Basic: Exercise-28 with Solution
Write a C# program to reverse the words of a sentence.
Sample Solution:-
C# Sharp Code:
using System;
using System.Collections.Generic;
public class Exercise28 {
public static void Main() {
string line = "Display the pattern like pyramid using the alphabet.";
Console.WriteLine("\nOriginal String: " + line);
string result = "";
List < string > wordsList = new List < string > ();
string[] words = line.Split(new [] {
" "
}, StringSplitOptions.None);
for (int i = words.Length - 1; i >= 0; i--) {
result += words[i] + " ";
}
wordsList.Add(result);
foreach(String s in wordsList) {
Console.WriteLine("\nReverse String: " + s);
}
}
}
Sample Output:
Original String: Display the pattern like pyramid using the alphabet. Reverse String: alphabet. the using pyramid like pattern the Display
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# program and compute the sum of the digits of an integer.
Next: Write a C# program to find the size of a specified file in bytes.
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