Alphabets

Java program to display alphabets using loops

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

if statement in Java language

Nested if statements in Java language

Method in Java language

For loop in Java language

While loop in Java language

Do-while loop in Java language

Operator in Java language

Variable in Java language

Data type in Java language

class and main method in Java

 

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

 

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.