Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Challenge 2: string exercise: Backwards Create a method in C# that prompts the u

ID: 3711548 • Letter: C

Question

Challenge 2: string exercise: Backwards Create a method in C# that prompts the user for a sentence that has at least 6 words in it. Your code should do the following:

1. Display to the user the sentence they have entered

2. Reverse the words in the sentence

3. Display to the user the sentence in reverse. For example, if the sentence was “Hello World” the output would be “dlroW olleH” ? User Input: Prompt the user to enter in a sentence with at least 6 words Validate six or more words have been entered Console Output: Display the sentence the user entered Use a method to reverse the sentence and output the result

Explanation / Answer

using System;      namespace reverseString   {       class Program       {           static void Main(string[] args)           {               string str = "", reverse = "";               int Length = 0;               Console.WriteLine("Enter a Word");               //Getting String(word) from Console               str = Console.ReadLine();               //Calculate length of string str   if(str.Lenght>=4){             Length = str.Length - 1;             while(Length>=0)               {                   reverse = reverse + str[Length];                   Length--;               }               //Displaying the reverse word               Console.WriteLine("Reverse word is {0}",reverse);               Console.ReadLine();   }else{    Console.WriteLine("Please Enter Atleast 4 character And Try Again"); }         }       }   }