ellapt

3.4.ThirdDigit7

Dec 14th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. using System;
  2.  
  3. class ThirdDigit7
  4. {
  5. static void Main()
  6. {
  7. Console.WriteLine("Check for given integer if its third digit (right-to-left) is 7.");
  8. Console.WriteLine("Please, enter an integer number: ");
  9. string inputInt = Console.ReadLine();
  10. int checkNum;
  11. if (int.TryParse(inputInt, out checkNum))
  12. {
  13. checkNum = Math.Abs(checkNum);
  14. if ( checkNum > 99)
  15. {
  16. checkNum /= 100;
  17. if (checkNum % 10 == 7)
  18. {
  19. Console.WriteLine("The number {0} HAS its third digit =7 (right-to-left).", inputInt);
  20. }
  21. else
  22. {
  23. Console.WriteLine("The number {0} HAS NOT its third digit =7 (right-to-left).", inputInt);
  24. }
  25. }
  26. else
  27. {
  28. Console.WriteLine("{0} has less than 3 digits!", inputInt);
  29. }
  30. }
  31. else
  32. {
  33. Console.WriteLine("{0} is not an integer number!", inputInt);
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment