In this article, we will discuss the concept of Program to display all Alphabet between given range using loops in Java programming language
In this post, we are going to learn how to display all the upper case(A to Z) and lower case (a to z) Alphabets between given range using the loops in Java language
The program displays all the upper case and lower case alphabet letters between given range using for loop in Java language
Program 1
import java.util.Scanner; public class Display_Alphabet_1{ public static void main(String args[]){ char ch,ch1,ch2;//char variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the Starting Alphabets: "); ch1=scan.next().charAt(0);//store entered first Alphabet in variale ch1 System.out.print("Enter the Ending Alphabets: "); ch2=scan.next().charAt(0);//store entered last Alphabet in variale ch2 for(ch=ch1; ch<=ch2; ch++){ System.out.print(ch+" "); //display Alphabets with space } } }
When the above code is executed, it produces the following result
Case 1
Enter the starting Alphabets: d Enter the Ending Alphabets: v d e f g h i j k l m n o p q r s t u v
Case 2
Enter the starting Alphabets: F Enter the Ending Alphabets: X F G H I J K L M N O P Q R S T U V W X
In the above program, we are using a for loop, this is used to print upper case Alphabet letters or lower case Alphabet letters in the given range
Approach
Program 2
The program displays all the upper case and lower case alphabet letters between given range using while loop in Java language
import java.util.Scanner; public class Display_Alphabet_2{ public static void main(String args[]){ char ch,ch1,ch2;//char variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the Starting Alphabets "); ch1=scan.next().charAt(0);//store entered first Alphabet in variale ch1 System.out.print("Enter the Ending Alphabets "); ch2=scan.next().charAt(0);//store entered last Alphabet in variale ch2 ch=ch1; while(ch<=ch2){ System.out.print(ch+" "); //display Alphabets with space ch++; } } }
When the above code is executed, it produces the following result
Case 1
Enter the starting Alphabets: c Enter the Ending Alphabets: l c d e f g h i j k l
Case 2
Enter the starting Alphabets: H Enter the Ending Alphabets: U H I J K L M N O P Q R S T U
In the above program, we are using a while loop, this is used to print upper case Alphabet letters or lower case Alphabet letters
Approach
Program 3
The program displays all the upper case and lower case alphabet letters between the given range using the do-while loop in Java language
import java.util.Scanner; public class Display_Alphabet_3{ public static void main(String args[]){ char ch,ch1,ch2;//char variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the Starting Alphabets "); ch1=scan.next().charAt(0);//store entered first Alphabet in variale ch1 System.out.print("Enter the Ending Alphabets "); ch2=scan.next().charAt(0);//store entered last Alphabet in variale ch2 ch=ch1; do{ System.out.print(ch+" "); //display Alphabets with space ch++; }while(ch<=ch2); } }
When the above code is executed, it produces the following result
Case 1
Enter the starting Alphabets: d Enter the Ending Alphabets: u d i j k l m n o p q r s t u
Case 2
Enter the starting Alphabets: J Enter the Ending Alphabets: Y J K L M N O P Q R S T U V W XY
In the above program, we are using a do-while loop, this is used to print upper case Alphabet letters or lower case Alphabet letters
Approach
Suggested for you
do-while loop in Java language
Similar post
Java program to print all upper case and lower case Alphabets
C++ program to print all upper case and lower case Alphabets
C program to print all upper case and lower case Alphabets
Java code to print all upper case and lower case Alphabets between the given range
C++ code to print all upper case and lower case Alphabets between the given range
C code to print all upper case and lower case Alphabets between the given range
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…