Difference between revisions of "Print Out the Alphabet"
From CompSciWiki
m |
|||
Line 1: | Line 1: | ||
{{1010PrAD|ProblemName=Print Out the Alphabet | {{1010PrAD|ProblemName=Print Out the Alphabet | ||
− | |Problem= | + | |Problem= You task is to print out the lower case letters of the aplhabet. You are only allowed to use one char variable and one println statement inside of a for loop. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
Line 40: | Line 11: | ||
An image or By Students section | An image or By Students section | ||
− | |Solution= | + | |Solution= To get the next letter in the alphabet you can add 1 each time to the char variable. |
<pre> | <pre> | ||
int numLetters = 26; | int numLetters = 26; | ||
− | char | + | char letter = 'a'; |
for(int i = 0; i < numLetters; i++) | for(int i = 0; i < numLetters; i++) | ||
− | System.out.println( | + | { |
+ | System.out.println(letter); | ||
+ | letter = letter + 1; | ||
+ | } | ||
</pre> | </pre> | ||
}} | }} |
Revision as of 13:14, 30 March 2010
Back to the Program-A-Day homepage
ProblemYou task is to print out the lower case letters of the aplhabet. You are only allowed to use one char variable and one println statement inside of a for loop. |
SideSectionTitle
An image or By Students section | |
---|---|---|
SolutionTo 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; } | ||
CodeSolutionCode goes here. Please DO NOT put your code in <pre> tags! |