Advertisement
tvarbanov

CSharp2-03-03

Jan 3rd, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2.  
  3. class LastDigitMethod
  4. {
  5.     //Write a method that returns the last digit of given integer as an English word. Examples: 512  "two", 1024  "four", 12309  "nine".
  6.  
  7.     static string LastDigit(int number)
  8.     {
  9.         int digit = number % 10; //Gets the last digit
  10.         switch (digit)
  11.         {
  12.             case 1:
  13.                 return "one";
  14.             case 2:
  15.                 return "two";
  16.             case 3:
  17.                 return "three";
  18.             case 4:
  19.                 return "four";
  20.             case 5:
  21.                 return "five";
  22.             case 6:
  23.                 return "six";
  24.             case 7:
  25.                 return "seven";
  26.             case 8:
  27.                 return "eight";
  28.             case 9:
  29.                 return "nine";
  30.             default:
  31.                 return "invalid input";
  32.         }
  33.     }
  34.  
  35.     static void Main()
  36.     {
  37.         //Get the number
  38.         Console.WriteLine("Enter your number : ");
  39.         int num = int.Parse(Console.ReadLine());
  40.         Console.WriteLine("Last digit is - {0}",LastDigit(num));
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement