Write a program to print reverse alphabets from Z to A
This Java program is used to print all the uppercase alphabets in the English language in reverse order. Here's a step-by-step breakdown of how the program works:
- The Reverse_Alphabet class is defined and the main method is declared.
- Inside the main method, a character variable s is declared but not initialized.
- The program enters a for loop that will execute as long as the value of s is greater than or equal to the character 'A'.
- Inside the for loop, the program prints the current value of s to the console using the println() method of the System.out object.
- The value of s is then decremented by one using the -- operator.
- The program returns to the beginning of the for loop and checks the condition again. If the value of s is still greater than or equal to the character 'A', the loop will continue to execute. If not, the loop will terminate and the program will exit.
Source Code
class Reverse_Alphabet
{
public static void main(String[] args)
{
char s;
for(s='Z';s>='A';s--)
{
System.out.println(s);
}
}
}
Output
Z
Y
X
W
V
U
T
S
R
Q
P
O
N
M
L
K
J
I
H
G
F
E
D
C
B
A