display all Alphabets
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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.