Advertisement
BackoChan

Домашно Methods - 3 задача

Dec 19th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. class LastDigitAsAWord
  4. {
  5. //Write a method that returns the last digit of given integer
  6. //as an English word.
  7. //Examples: 512  "two", 1024  "four", 12309  "nine".
  8.  
  9.     static void WordLastDigit(int lastDigit) // In this method we print the last digit as a word.
  10.     {
  11.         string[] array = new string[] {"Zero",
  12.             "One", "Two", "Three", "Four",
  13.             "Five", "Six", "Seven", "Eight",
  14.             "Nine", "Ten"
  15.         };
  16.         Console.WriteLine("The last digit is {0} !", array[lastDigit]);
  17.     }
  18.     private static int GetLastDigit() // here we calculate the last digit
  19.     {
  20.         Console.Write("Enter a number: ");
  21.         int number = int.Parse(Console.ReadLine());
  22.         int reminder = number % 10;
  23.         return reminder;
  24.     }
  25.     static void Main()
  26.     {
  27.         WordLastDigit(GetLastDigit()); // execute the two methods.
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement