Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C program to display all Alphabets in given range using loops

Java program to print all alphabets in given range using loops

Posted on February 12, 2022February 21, 2022

Table of Contents

  • Java program to print all alphabets in given range using loops
    • Code to print all alphabets in given range
      • Code to print all alphabets in given range using for loop
      • Code to print all alphabets in given range using while loop
      • Code to print all alphabets in given range using do-while loop

Java program to print all alphabets in given range using loops

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

Code to print all alphabets in given range

Code to print all alphabets in given range using for loop

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

 

Code to print all alphabets in given range using while loop

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

 

Code to print all alphabets in given range using do-while loop

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

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

 

 

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes