Write a program that takes data, a word at a time and reverses the words of the line. Sample input/output dialogue: Input string value: birds and bees Reversed: bees and birds
using System;
namespace Questions
{
class Program
{
static void Main()
{
Console.Write("Input string value: ");
string stringValue = Console.ReadLine();
string[] words = stringValue.Split();
string reversedWords = string.Empty;
for(int i = words.Length-1; i>=0; i--)
{
reversedWords += words[i];
if (i != 0)
reversedWords += " ";
}
Console.WriteLine("\nReversed: "+ reversedWords);
Console.ReadKey();
}
}
}
Comments
Leave a comment