Answer to Question #180656 in C# for Patrick Ian Kyle Mabunay

Question #180656

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


1
Expert's answer
2021-04-16T11:05:02-0400
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();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS