Table of Contents
Java program to display alphabets using loops
In this article, we will discuss the concept of Java program to display all alphabets using loops
In this post, we are going to learn how to write a program to print all characters of English alphabet using for, while and do-while loop in Java language
Code to print all characters of alphabet
Code to print all characters of alphabet using for loop
In this code, we are going to learn how to print all characters of English alphabet using for loop in Java language
Program 1
public class Disp_Alphabet_LetAtoZ{ public static void main(String args[]){ char ch;// declare character variable System.out.print("Display Uppercase Alphabets \n"); for(ch='A'; ch<='Z'; ch++){ System.out.print(ch+" "); //display uppercase Alphabets with space using for loop } System.out.print("\n\nDisplay Lowercase Alphabets \n"); for(ch='a'; ch<='z'; ch++){ System.out.print(ch+" "); //display lowercase Alphabets with space using for loop } } }
When the above code is executed, it produces the following result
Display Uppercase Alphabets 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 Display Lowercase Alphabets 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
Code to print all characters of alphabet using while loop
In this code, we are going to learn how to print all characters of English alphabet using while loop in Java language
Program 2
public class Disp_Alpha_LetAtoZ{ public static void main(String args[]){ char ch;// declare character variable System.out.print("Display Uppercase Alphabets \n"); ch='A'; while(ch<='Z'){ System.out.print(ch+" "); //display uppercase Alphabets with space using while loop ch++; } System.out.print("\n\nDisplay Lowercase Alphabets \n"); ch='a'; while(ch<='z'){ System.out.print(ch+" "); //display lowercase Alphabets with space using while loop ch++; } } }
When the above code is executed, it produces the following result
Display Uppercase Alphabets 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 Display Lowercase Alphabets 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
Code to print all characters of alphabet using do-while loop
In this code, we are going to learn how to print all characters of English alphabet using do-while loop in Java language
Program 3
public class Disp_Alpha_LetterAtoZ{ public static void main(String args[]){ char ch;// declare character variable System.out.print("Display Uppercase Alphabets \n"); ch='A'; do{ System.out.print(ch+" "); //display uppercase Alphabets with space using o-while loop ch++; }while(ch<='Z'); System.out.print("\n\nDisplay Lowercase Alphabets \n"); ch='a'; do{ System.out.print(ch+" "); //display lowercase Alphabets with space using do-while loop ch++; }while(ch<='z'); } }
When the above code is executed, it produces the following result
Display Uppercase Alphabets 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 Display Lowercase Alphabets 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
Suggested post
Nested if statements in Java language
Do-while loop in Java language
Similar post
Java program to print all alphabets in given range
C program to print all alphabets in given range
C++ program to print all alphabets in given range
Java program to print all alphabets using loops
C program to print all alphabets using loops
C++ program to print all alphabets using loops