You are here

Java program to print alphabets

Java program to print alphabets on screen, i.e., a, b, c, ..., z; in lower case.

Java source code

  1. class Alphabets
  2. {
  3.    public static void main(String args[])
  4.    {
  5.       char ch;
  6.  
  7.       for (ch = 'a'; ch <= 'z'; ch++)
  8.          System.out.println(ch);
  9.    }
  10. }

You can easily modify the above java program to print alphabets in upper case.

Download Alphabets program class file.

Output of program:
Java program to print alphabets output

Printing alphabets using a while loop (Only the body of the main method is shown):

  1. char c = 'a';
  2.  
  3. while (c <= 'z') {
  4.   System.out.println(c);
  5.   c++;
  6. }

Using a do while loop:

  1. char c = 'A';
  2.  
  3. do {
  4.   System.out.println(c);
  5.   c++;
  6. } while (c <= 'Z');