Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /* Напишете програма, която проверява дали на трета позиция, от ляво на дясно,
- числото съдържа цифрата 7.Направете проверка дали числото е от 5 цифри.
- Ако съдържа цифрата -> true, ако не я съдържа на трета позиция, но я има изпишете броя.
- Ако не я съдържа (като цяло) също го отбележете.*/
- class IsThirdDigitSeven
- {
- static void Main()
- {
- Console.WriteLine("Write a number of five digits:");
- string number = Console.ReadLine();
- IsSevenDigitsNumber(number);
- }
- static void IsSevenDigitsNumber(string number)
- {
- if(number.Length > 5 || number.Length < 5)
- {
- Console.WriteLine( "Write a number of 5 digits");
- number = Console.ReadLine();
- IsSevenDigitsNumber(number);
- }
- else if (number.Length == 5)
- {
- CheckContentSeven(number);
- }
- }
- static void CheckContentSeven(string checkDigit)
- {
- int counter = 0;
- int counter2 = 0;
- bool isThirdPos = false;
- for (int i = 0; i < checkDigit.Length; i++)
- {
- if(checkDigit[i] == '7')
- {
- counter++;
- if(i == 2)
- {
- isThirdPos = true;
- break;
- }
- }
- if (checkDigit[i] != '7')
- {
- counter2++;
- }
- }
- if (counter2 == checkDigit.Length)
- {
- Console.WriteLine("No contents the digit seven at all");
- }
- else if (isThirdPos)
- {
- Console.WriteLine("The number contents digit 7 at third position -> {0}", isThirdPos);
- }
- else if (!isThirdPos)
- {
- Console.WriteLine("The number contents 7, {0} times, but at the third position -> {1}", counter, isThirdPos);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment