encho253

Stars

Aug 6th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5.     public class Program
  6.     {
  7.         public static void Main()
  8.         {
  9.             int length = int.Parse(Console.ReadLine());        
  10.             string star = "* ";
  11.             string whiteSpace = " ";
  12.  
  13.             PrintTriangleUp(length, star, whiteSpace);
  14.             PrintTriangleDown(length, star, whiteSpace);
  15.         }
  16.  
  17.         public static void PrintTriangleUp(int length, string star, string whiteSpace)
  18.         {
  19.             int whiteSpaceLength = length - 1;
  20.  
  21.             for (int i = 1; i <= length; i++)
  22.             {
  23.                 PrintWhiteSpace(whiteSpaceLength, whiteSpace);
  24.                 whiteSpaceLength -= 1;
  25.                 PrintStars(i, star);
  26.  
  27.                 Console.WriteLine();
  28.             }
  29.         }
  30.  
  31.         public static void PrintTriangleDown(int length, string star, string whiteSpace)
  32.         {
  33.             length -= 1;
  34.             int whiteSpaceLength = 1;
  35.  
  36.             for (int i = length; i >= 0; i--)
  37.             {
  38.                 PrintWhiteSpace(whiteSpaceLength, whiteSpace);
  39.                 whiteSpaceLength += 1;
  40.                 PrintStars(i, star);
  41.  
  42.                 Console.WriteLine();
  43.             }
  44.         }
  45.  
  46.         public static void PrintWhiteSpace(int whiteSpaceLength, string whiteSpace)
  47.         {
  48.             for (int i = 0; i < whiteSpaceLength; i++)
  49.             {
  50.                 Console.Write(whiteSpace);
  51.             }
  52.         }
  53.  
  54.         public static void PrintStars(int starsLength, string star)
  55.         {
  56.             for (int i = 0; i < starsLength; i++)
  57.             {
  58.                 Console.Write(star);
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment