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