Venciity

[C#] Домашно Arrays - 12 Задача

Jan 9th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. /* Write a program that creates an array containing
  2.  * all letters from the alphabet (A-Z). Read a word
  3.  * from the console and print the index of each of its letters in the array.
  4.  */
  5.  
  6. using System;
  7.  
  8. class LetterIndex
  9. {
  10.     static void Main()
  11.     {
  12.         int[] letterIndexes = new int[53];
  13.         //lowercase
  14.         for (int i = 1; i < letterIndexes.Length / 2 + 1; i++)
  15.         {
  16.             letterIndexes[i] = ('a' - 1) + i;
  17.         }
  18.         //Upercase
  19.         for (int i = letterIndexes.Length / 2 + 1, k = 0; i < letterIndexes.Length; i++, k++)
  20.         {
  21.             letterIndexes[i] = 'A' + k;
  22.         }
  23.  
  24.         //Letter check
  25.         Console.Write("enter word : ");
  26.         string testWord = (Console.ReadLine());
  27.        
  28.         for (int i = 0; i < testWord.Length; i++)
  29.         {
  30.             for (int j = 0; j < letterIndexes.Length; j++)
  31.             {
  32.                 if (testWord[i] == letterIndexes[j])
  33.                 {
  34.                     Console.WriteLine("Leter {0} has index: {1}", testWord[i], j);
  35.                     break;
  36.                 }
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment