Join our newsletter for the latest updates.

Java Program to Display Characters from A to Z using loop

In this program, you'll learn to print English alphabets using for loop in Java. You'll also learn learn to print only uppercased and lowercased alphabets.

To understand this example, you should have the knowledge of the following Java programming topics:


Example 1: Display Uppercased A to Z using for loop

public class Characters {

    public static void main(String[] args) {

        char c;

        for(c = 'A'; c <= 'Z'; ++c)
            System.out.print(c + " ");
    }
}

Output

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 

You can loop through A to Z using for loop because they are stored as ASCII characters in Java.

So, internally, you loop through 65 to 90 to print the English alphabets.

With a little modification, you can display lowercased alphabets as shown in the example below.


Example 2: Display Lowercased a to z using for loop

public class Characters {

    public static void main(String[] args) {

        char c;

        for(c = 'a'; c <= 'z'; ++c)
            System.out.print(c + " ");
    }
}

Output

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 

You simply replace 'A' with 'a' and 'Z' with 'z' to display the lowercased alphabets. In this case, internally you loop through 97 to 122.