原文: https://www.programiz.com/java-programming/examples/display-alphabets
public class Characters {
public static void main(String[] args) {
char c;
for(c = 'A'; c <= 'Z'; ++c)
System.out.print(c + " ");
}
}运行该程序时,输出为:
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 您可以使用for循环在 A 到 Z 之间循环,因为它们在 Java 中存储为 ASCII 字符。
因此,在内部,您可以在 65 到 90 之间循环打印英文字母。
稍加修改即可显示小写字母,如下例所示。
public class Characters {
public static void main(String[] args) {
char c;
for(c = 'a'; c <= 'z'; ++c)
System.out.print(c + " ");
}
}运行该程序时,输出为:
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 您只需将"A"替换为"a",将"Z"替换为"z"以显示小写字母。 在这种情况下,您会在内部循环通过 97 到 122。