Advertisement
ellapt

T7.12.WordLettersIndexes

Jan 15th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. using System;
  2. class WordLettersIndexes
  3. {
  4. static void Main()
  5. {
  6. int[] lettCodeNum = new int[53];
  7. // small letters first
  8. for (int i = 0; i < 27; i++)
  9. {
  10. lettCodeNum[i+1] = 'a' + i;
  11. }
  12. // capital letters immediately after
  13. for (int i = 27, j = 0; i < 53; i++,j++)
  14. {
  15. lettCodeNum[i] = 'A' + j;
  16. }
  17.  
  18. string checkWord="";
  19. Console.WriteLine("Read a word from the console, print the index of its letters in the alphabet.");
  20. Console.Write("Enter a word: ");
  21. checkWord = Console.ReadLine();
  22.  
  23. for (int i = 0; i < checkWord.Length; i++)
  24. {
  25. for (int j = 1; j < 53; j++)
  26. {
  27. if (checkWord[i] == lettCodeNum[j])
  28. {
  29. Console.WriteLine("Leter {0} has index: {1}", checkWord[i], j );
  30. break;
  31. }
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement