For Loops

In this example, ch is a char (character) starts with 'a' and continues to print up to 'z'.

1
2
3
4
5
6
7
8
9
10
11
//for loop prints the alphabet 
package characters;
public class Alphabet {
  public static void main(String[] args) {
	char ch; //used to 'drive' the loop
	for (ch = 'a'; ch<='z'; ch++) { 
       System.out.print(ch);
    }//loop
    System.out.println();
  }//main
}//class
CODE
Output:
abcdefghijklmnopqrstuvwxyz

Can you print the alphabet backwards?

NEXT: Self study questions