Java program to print alphabets

Created with Sketch.

 

Java program to print alphabets

Java program to print letters (i.e., a, b, c, …, z in lower case) on the screen using a loop.

Java program

class Alphabets
{
public static void main(String args[])
{
char t;

for (t = ‘a’; t <= ‘z’; t++) // For upper case use ‘A’ and ‘Z’
System.out.println(t);
}
}

You can modify the program to print them in upper case.

 

Output of program:
Java program to print alphabets output

Printing alphabets using a while loop (The code snippet shows only the body of the main method):

char c = ‘a’;

while (c <= ‘z’) {
System.out.println(c);
c++;
}

Using a do while loop:

char c = ‘A’;

do {
System.out.println(c);
c++;
} while (c <= ‘Z’);

Leave a Reply

Your email address will not be published. Required fields are marked *