Table of Contents
In this article, we will discuss the concept of Java program to print all alphabets in given range using loops
In this post, we are going to learn how to write a program to print all alphabets in given range using for, while and do-while loop in Java language
In this code, we are going to learn how to print all alphabets in given range using for loop in Java language
Program 1
import java.util.Scanner; public class Display_Alphabet_Letters{ public static void main(String args[]){ char ch,ch1,ch2;// declare character variable Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the Starting Alphabets: "); //ask starting alphabet from user ch1=scan.next().charAt(0); //Reading starting alphabets from user System.out.print("Enter the Ending Alphabets "); //ask ending alphabet from user ch2=scan.next().charAt(0); //Reading ending alphabets from user System.out.print("Display Alphabets between"+ch1+" and "+ch2+" : \n"); for(ch=ch1; ch<=ch2; ch++){ System.out.print(ch+" "); //display uppercase Alphabets with space using for loop } } }
When the above code is executed, it producing the following result
Enter the Starting Alphabets: C Enter the Ending Alphabets: M Display Alphabets between C and M : C D E F G H I J K L M
In this code, we are going to learn how to print all alphabets in given range using while loop in Java language
Program 2
import java.util.Scanner; public class Disp_Alphabet_Let1{ public static void main(String args[]){ char ch,ch1,ch2;// declare character variable Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the Starting Alphabets "); //ask starting alphabet from user ch1=scan.next().charAt(0); //Reading starting alphabets from user System.out.print("Enter the Ending Alphabets "); //ask ending alphabet from user ch2=scan.next().charAt(0); //Reading ending alphabets from user System.out.print("Display Alphabets between "+ch1+" and "+ch2+" : \n"); ch=ch1; while(ch<=ch2){ System.out.print(ch+" "); //display uppercase Alphabets with space using while loop ch++; } } }
When the above code is executed, it producing the following result
Enter the Starting Alphabets: S Enter the Ending Alphabets: Z Display Alphabets between S and Z : S T U V W X Y Z
In this code, we are going to learn how to print all alphabets in given range using do-while loop in Java language
Program 3
import java.util.Scanner; public class Disp_Alphabet_Let2{ public static void main(String args[]){ char ch,ch1,ch2;// declare character variable Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the Starting Alphabets "); //ask starting alphabet from user ch1=scan.next().charAt(0); //Reading starting alphabets from user System.out.print("Enter the Ending Alphabets "); //ask ending alphabet from user ch2=scan.next().charAt(0); //Reading ending alphabets from user System.out.print("Display Alphabets between "+ch1+" and "+ch2+" : \n"); ch=ch1; do{ System.out.print(ch+" "); //display uppercase Alphabets with space using do-while loop ch++; }while(ch<=ch2); } }
When the above code is executed, it producing the following result
Enter the Starting Alphabets: D Enter the Ending Alphabets: M Display Alphabets between D and M : D E F G H I J K L M
Suggested post
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
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.