Print Out the Alphabet

From CompSciWiki
Revision as of 12:45, 30 March 2010 by EricE (Talk | contribs)

Jump to: navigation, search

Back to the Program-A-Day homepage

Problem

Print out the alphabet using only 4 lines of code.

System.out.println("a");
System.out.println("b");
System.out.println("c");
System.out.println("d");
System.out.println("e");
System.out.println("f");
System.out.println("g");
System.out.println("h");
System.out.println("i");
System.out.println("j");
System.out.println("k");
System.out.println("l");
System.out.println("m");
System.out.println("n");
System.out.println("o");
System.out.println("p");
System.out.println("q");
System.out.println("r");
System.out.println("s");
System.out.println("t");
System.out.println("u");
System.out.println("v");
System.out.println("w");
System.out.println("x");
System.out.println("y");
System.out.println("z");
 

SideSectionTitle

float
Taken from http://www.flickr.com/photos/daniello/565304023/

An image or By Students section

Solution

int numLetters = 26;
char alphabet[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

for(int i = 0; i < numLetters; i++)
    System.out.println(alphabet[i]);

Code

SolutionCode goes here. Please DO NOT put your code in <pre> tags!

Back to the Program-A-Day homepage