SHARE
TWEET

12. LetterIndex

Teodor92 Jan 6th, 2013 708 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         //Letter chercker
  24.         string testWord = "TSYZ";
  25.         for (int i = 0; i < testWord.Length; i++)
  26.         {
  27.             for (int j = 0; j < letterIndexes.Length; j++)
  28.             {
  29.                 if (testWord[i] == letterIndexes[j])
  30.                 {
  31.                     Console.WriteLine("Leter {0} has index: {1}", testWord[i], j );
  32.                     break;
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top