Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 7. Repeat String
- 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)
- Example
- Input Output
- abc
- 3 abcabcabc
- String
- 2 StringString
- Hints
- 1. Firstly read the string and the repeat count n
- 2. Then create the method and pass it the variables
- using System;
- namespace _07RepeatString
- {
- class Program
- {
- static void Main(string[] args)
- {
- string word = Console.ReadLine();
- var number = int.Parse(Console.ReadLine());
- string concatenation = RepeatString(word, number);
- Console.WriteLine(concatenation);
- }
- private static string RepeatString(string word, int number)
- {
- string result = "";
- for (int i = 0; i < number; i++)
- {
- result += word;
- }
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment