Advertisement
Krissy

12. AlphabetArray

Jan 7th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2.  
  3. class ArrayAlphabet
  4. {
  5.     static void Main()
  6.     {
  7.         char[] alphabet = new char[27]; //creates the array
  8.         int initializizationOfArray=65; //'A' has value of 65.
  9.         //fills the array
  10.         for (int i = 1; i < 27; i++)
  11.         {
  12.             alphabet[i] = (char) initializizationOfArray;
  13.             initializizationOfArray++;
  14.         }
  15.        
  16.         Console.WriteLine("Please enter a word with capital letters:");  
  17.          
  18.         string enteredWord = Console.ReadLine().ToUpper();
  19.         //print the index of each of the letters of the word
  20.         foreach (char letter in enteredWord)
  21.         {
  22.             for (int i = 1; i < 27; i++)
  23.             {
  24.                 if (alphabet[i]==letter)
  25.                 {
  26.                     Console.WriteLine("The index of the letter {0} is {1}", letter,i);
  27.             break; 
  28.                 }                
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement