Advertisement
adriyanbulgary

OperatorsExpressionsAndStatements - Task 5

Jun 13th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2. /*
  3. *Write an expression that checks for given integer if its third digit from right-to-left is 7
  4. */
  5.  
  6. class ThirdDigitSeven
  7. {
  8.     static void Main()
  9.     {
  10.         int numberOne = 1732;
  11.         int numberTwo = 15691;
  12.         bool thirdDigit;
  13.         if (thirdDigit = (numberOne / 100) % 10 == 7)
  14.         {
  15.             Console.WriteLine("The third digit of {0} is 7", numberOne);
  16.         }
  17.         else
  18.         {
  19.             Console.WriteLine("The third digit is not 7");
  20.         }
  21.         if (thirdDigit = (numberTwo / 1000) % 10 == 7)
  22.         {
  23.             Console.WriteLine("The third digit of {0} is 7", numberTwo);
  24.         }
  25.         else
  26.         {
  27.             Console.WriteLine("The third digit of {0} is not 7", numberTwo);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement