JulianJulianov

07.MetodsLab-Repeat String

Feb 13th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. 7. Repeat String
  2. Write a method that receives a string and a repeat count n (integer). The method should return a new string (the old one repeated n times)
  3. Example
  4. Input      Output
  5. abc
  6. 3          abcabcabc
  7. String
  8. 2          StringString
  9. Hints
  10. 1.  Firstly read the string and the repeat count n
  11. 2.  Then create the method and pass it the variables
  12.  
  13. using System;
  14.  
  15. namespace _07RepeatString
  16. {
  17.     class Program
  18.     {
  19.         static void Main(string[] args)
  20.         {
  21.             string word = Console.ReadLine();
  22.             var number = int.Parse(Console.ReadLine());
  23.             string concatenation = RepeatString(word, number);
  24.             Console.WriteLine(concatenation);
  25.         }
  26.  
  27.         private static string RepeatString(string word, int number)
  28.         {
  29.            string result = "";
  30.             for (int i = 0; i < number; i++)
  31.             {
  32.                result += word;
  33.             }
  34.             return result;
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment