Difference between revisions of "Print Out the Alphabet"

From CompSciWiki
Jump to: navigation, search
Line 3: Line 3:
 
|Problem=Print out the entire lower case letters of the aplhabet.
 
|Problem=Print out the entire lower case letters of the aplhabet.
 
Use the following guidelines in coming up with a solution:
 
Use the following guidelines in coming up with a solution:
* [[https://wiki1010.cs.umanitoba.ca/mediawiki/index.php/Common_Primitive_Variables#Primitive_Type_char|character]] for printing out the alphabet.
+
* [[Common Primitive Variables|character]] for printing out the alphabet.
 
* Input with [[Strings]].
 
* Input with [[Strings]].
 
* [[Comments|Commenting]] our code.
 
* [[Comments|Commenting]] our code.

Revision as of 13:59, 6 April 2010

Back to the Program-A-Day homepage

Problem

Print out the entire lower case letters of the aplhabet. Use the following guidelines in coming up with a solution:

 

While and For Loops

Wiki loops01.jpg

Solution

To get the next letter in the alphabet you can add 1 each time to the char variable.

int numLetters = 26;
char letter = 'a';

for(int i = 0; i < numLetters; i++)
{
    System.out.println(letter);
    letter = letter + 1;
}

Code

Solution Code

Back to the Program-A-Day homepage