Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EXAM_2_LAB_KIAN_LUETKE
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Parameters
- int k, n;
- string s;
- UserInput(out s, out k, out n);
- Console.WriteLine("****************RESULTS****************");
- /**Excersise Test Cases**/
- //Test Case One
- Console.WriteLine(PrintKandN(s, k, n));
- //Test Case Two
- Console.WriteLine(PrintPrefix(s, k));
- //Test Case Three
- Console.WriteLine(PrintKCharsNTimes(s, k, n));
- Console.ReadKey();
- }
- //Task One
- public static string PrintKandN(string s, int k, int n)
- {
- return s[k] + new String('+', k) + s[n];
- }
- //Task Two
- public static string PrintPrefix(string s, int k)
- {
- return s.Substring(0, k);
- }
- //Task Three
- public static string PrintKCharsNTimes(string s, int k, int n)
- {
- return string.Concat(Enumerable.Repeat(s.Substring(0, k), n));
- }
- public static void UserInput(out string s, out int k, out int n)
- {
- //Init parameters
- k = 0; n = 0;
- Console.WriteLine("Please input a String s, an Integer k and an Interger n. Confirm each with the Enter Key on your Keyboard\n");
- Console.Write("String s: ");
- s = Console.ReadLine();
- bool kIsInteger = false, nIsInteger = false;
- while (!kIsInteger)
- {
- Console.Write("Integer k: ");
- kIsInteger = int.TryParse(Console.ReadLine(),out k);
- }
- while (!nIsInteger)
- {
- Console.Write("Integer n: ");
- nIsInteger = int.TryParse(Console.ReadLine(),out n);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement