Last active
November 26, 2016 22:24
-
-
Save Soulstorm50/16ecfea06a22a35d1f1205471b3e9768 to your computer and use it in GitHub Desktop.
C# Лесенка
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
StairBuilder xxx = new StairBuilder(); | |
xxx.Start(); | |
} | |
} | |
class StairBuilder | |
{ | |
private int spaceCount = 0; | |
public void Start() | |
{ | |
Console.WriteLine("Enter the number of stairs: "); | |
string userText = Console.ReadLine(); | |
bool onlyDigits = true; | |
foreach (var item in userText) | |
{ | |
if (!Char.IsDigit(item)) | |
{ | |
onlyDigits = false; | |
Console.WriteLine("\nWrong symbol: " + item + ". Only digits are allowed.\n"); | |
break; | |
} | |
} | |
if (onlyDigits) | |
{ | |
int stairCount = Convert.ToInt32(userText); | |
for (int i = 0; i < stairCount; i++) | |
OutPutStair(); | |
OutPutWhiteSpaces(); | |
Console.WriteLine("***\n"); | |
} | |
} | |
private void OutPutWhiteSpaces() | |
{ | |
for (int i = 0; i < spaceCount; i++) | |
Console.Write(" "); | |
} | |
private void OutPutStair() | |
{ | |
OutPutWhiteSpaces(); | |
Console.WriteLine("***"); | |
OutPutWhiteSpaces(); | |
Console.WriteLine(" *"); | |
spaceCount += 2; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment