svetlozar_kirkov

Print Last Digit of Int (Exercise)

Oct 3rd, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5.  
  6. namespace ConsoleTesting3
  7. {
  8.     class ConsoleTesting3
  9.     {
  10.         private static void Main()
  11.         {
  12.             PrintLastDigit(int.Parse(Console.ReadLine()));
  13.         }
  14.  
  15.         static void PrintLastDigit(int number)
  16.         {
  17.             string temp = number.ToString();
  18.             string lastDigit = Convert.ToString(temp[temp.Length-1]);
  19.             switch (lastDigit)
  20.             {
  21.                 case "1":
  22.                     lastDigit = "one";
  23.                     break;
  24.                 case "2":
  25.                     lastDigit = "two";
  26.                     break;
  27.                 case "3":
  28.                     lastDigit = "three";
  29.                     break;
  30.                 case "4":
  31.                     lastDigit = "four";
  32.                     break;
  33.                 case "5":
  34.                     lastDigit = "five";
  35.                     break;
  36.                 case "6":
  37.                     lastDigit = "six";
  38.                     break;
  39.                 case "7":
  40.                     lastDigit = "seven";
  41.                     break;
  42.                 case "8":
  43.                     lastDigit = "eight";
  44.                     break;
  45.                 case "9":
  46.                     lastDigit = "nine";
  47.                     break;
  48.                 case "0":
  49.                     lastDigit = "zero";
  50.                     break;
  51.  
  52.             }
  53.  
  54.             Console.WriteLine(lastDigit);
  55.  
  56.         }
  57.  
  58.        
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment