Advertisement
mzografski

OddOrEven

Mar 15th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. //Write an expression that checks if given integer is odd or even. Examples:
  4. class OddOrEven
  5. {
  6.     static void Main()
  7.     {
  8.         int intToCheck;
  9.         Console.WriteLine("Enter an integer to check:");        
  10.         while(!int.TryParse(Console.ReadLine(), out intToCheck))
  11.         {
  12.             Console.WriteLine("Please, provide a correct integer");
  13.         }
  14.         int intLenght = intToCheck.ToString().Length;
  15.         bool isOdd =  (intToCheck%2 == 0);
  16.         Console.WriteLine();
  17.         Console.Write(" N".PadRight(intLenght));
  18.         Console.Write("Odd?");        
  19.         Console.WriteLine();
  20.         Console.WriteLine("\n{0} : {1}", intToCheck.ToString().PadRight(intLenght), isOdd);
  21.         Console.WriteLine("\nPress any key to exit.");
  22.         Console.ReadKey();
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement