Friday, February 26, 2016

make a frame in c#

Problem:

Write a function that takes a list of strings an prints them, one per line, in a rectangular frame. For example the list ["Hello", "World", "in", "a", "frame"] gets printed as:
*********
* Hello *
* World *
* in    *
* a     *
* frame *
*********





Solution:

using System.Text;
using System.Threading.Tasks;

namespace helloWorldInAFrame
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("*********************");
            Console.WriteLine("*" + "         " + "Hallo " +"   " +"**");
            Console.WriteLine("*" + "       " + "world " + "    " + "***");
            Console.WriteLine("*" + "             " + "in " + " " + "***");
            Console.WriteLine("*" + "         " + "A Frame " + " " + "**");
            Console.WriteLine("*********************");
            Console.ReadKey();
        }
    }
}


Result:

No comments:

Post a Comment