English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java Flow Control

Java Arrays

Java Object-Oriented (I)

Java Object-Oriented (II)

Java Object-Oriented (III)

Java Exception Handling

Java List (List)

Java Queue (Queue)

Java Map Collection

Java Set Collection

Java Input Output (I/O)

Java Reader/Writer

Java Other Topics

Java program uses a loop to display characters from A to Z

Comprehensive List of Java Examples

In this program, you will learn how to use the for loop to print English letters in Java. You will also learn to print both uppercase and lowercase letters.

Example1Use the for loop to display uppercase A to Z

public class Characters {
    public static void main(String[] args) {
        char c;
        for(c = 'A'; c <= 'Z'; ++c)
            System.out.print(c + " '' ");
    }
}

When the program is run, the output is:

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 iterate between A and Z using for loop because they are stored as ASCII characters in Java.

Therefore, internally, you can65to9between 0 and print English letters.

You can modify it slightly to display lowercase letters, as shown in the following example.

Example2: Display lowercase 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 + " '' ");
    }
}

When the program is run, the output is:

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 only need to replace 'A' with 'a' and 'Z' with 'z' to display lowercase letters. In this case, you will iterate through the internal loop by97to122.

Comprehensive List of Java Examples