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;
- /* #6. Write a program that reads from the console a string of maximum 20 characters. If the length of the string is less than 20, the rest of the characters should be filled with '*'. Print the result string into the console. */
- class FillTo20WithStars
- {
- static void Main()
- {
- Console.WriteLine("Please enter below a string with maximum of 20 characters:");
- string inputString = Console.ReadLine();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < inputString.Length; i++)
- { sb.Append(inputString[i]); }
- for (int j = 1; j < 20 - inputString.Length + 1; j++)
- { sb.Append('*'); }
- string outputString = sb.ToString();
- Console.WriteLine("The resulting string is:");
- Console.WriteLine(outputString);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement