Answer to Question #212104 in C# for Goodman Gman

Question #212104

Create a new application that performs a shift and replacement of the letters in a string and then prints the result. The Main method of the application is provided below. Your task is to define the Shift and Replace methods that are called from Main. static void Main(string[] args) { string sAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Console.Write("Enter any word: "); string sInput = Console.ReadLine(); Console.Write("Enter n: "); int n = int.Parse(Console.ReadLine()); string sShift = Shift(sInput, n); Console.WriteLine("\n" + Replace(sShift, n, sAlphabet)); Console.Write("\nPress any key to exit."); Console.ReadKey(); } Shift accepts two parameters and returns a string in which all the characters of a string (first parameter) have been shifted n (second parameter) places to the right, with the last n letters looping back around to the beginning. For example, if the user enters ZUCCHINI for sInput and 3 for n, Shift must return INIZUCCH.


1
Expert's answer
2021-06-30T07:12:41-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;




namespace Q212104
{


    
    class Program
    {


        static void Main(string[] args)
        {
            
            Console.Write("Enter any word: "); 
            string sInput = Console.ReadLine(); 
            Console.Write("Enter n: "); 
            int n = int.Parse(Console.ReadLine()); 
            string sShift = Shift(sInput, n);
            Console.WriteLine("\n" + sShift); 
            Console.Write("\nPress any key to exit."); 
            
            Console.ReadKey(); 
        }


  
        private static string Shift(string sInput, int n)
        {


            return sInput.Substring(sInput.Length - n, n) + sInput.Substring(0, sInput.Length - n);
        }
    }
}

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