Java program to display alphabets (A to Z) using loop
Write a java program to display alphabets (A to Z) using loop
In this program, we can loop through A to Z using for loop because they are stored as ASCII characters in java.
This java program iterates the ASCII code from 65 to 90, representing the alphabets A to Z and print them.
With a little modification you can display lowercase alphabets to simply replace the A with a and Z with z. In this case, internally your loop through 97 to 122.
- Program:
class Main {
public static void main(String[] args) {
char n;
for(n = 'A'; n <= 'Z'; ++n) // For lowercase: for(n = 'a'; n <= 'b'; ++n)
System.out.print(n + " ");
}
}
- 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
0 comments