Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace EXAM_2_LAB_KIAN_LUETKE
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. //Parameters
  15. int k, n;
  16. string s;
  17. UserInput(out s, out k, out n);
  18.  
  19. Console.WriteLine("****************RESULTS****************");
  20.  
  21. /**Excersise Test Cases**/
  22. //Test Case One
  23. Console.WriteLine(PrintKandN(s, k, n));
  24. //Test Case Two
  25. Console.WriteLine(PrintPrefix(s, k));
  26. //Test Case Three
  27. Console.WriteLine(PrintKCharsNTimes(s, k, n));
  28.  
  29.  
  30.  
  31. Console.ReadKey();
  32. }
  33.  
  34. //Task One
  35. public static string PrintKandN(string s, int k, int n)
  36. {
  37. return s[k] + new String('+', k) + s[n];
  38. }
  39. //Task Two
  40. public static string PrintPrefix(string s, int k)
  41. {
  42. return s.Substring(0, k);
  43. }
  44. //Task Three
  45. public static string PrintKCharsNTimes(string s, int k, int n)
  46. {
  47. return string.Concat(Enumerable.Repeat(s.Substring(0, k), n));
  48. }
  49.  
  50. public static void UserInput(out string s, out int k, out int n)
  51. {
  52. //Init parameters
  53. k = 0; n = 0;
  54. Console.WriteLine("Please input a String s, an Integer k and an Interger n. Confirm each with the Enter Key on your Keyboard\n");
  55. Console.Write("String s: ");
  56. s = Console.ReadLine();
  57. bool kIsInteger = false, nIsInteger = false;
  58. while (!kIsInteger)
  59. {
  60. Console.Write("Integer k: ");
  61. kIsInteger = int.TryParse(Console.ReadLine(),out k);
  62. }
  63. while (!nIsInteger)
  64. {
  65. Console.Write("Integer n: ");
  66. nIsInteger = int.TryParse(Console.ReadLine(),out n);
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement