
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display Alphabets A to Z Using Loop in Java
In this article, we will understand how to print alphabets from A to Z or a to z in Java. This is accomplished using a simple for loop.
Below is a demonstration of the same −
Input
Suppose our input is −
A to Z
Output
The desired output would be −
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
Algorithm
Step1- Start Step 2- Declare a character: my_temp Step 3- Run a for loop from A to Z and print the values using the increment operator Step 4- Display the result Step 5- Stop
Example 1
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
public class Alphabets { public static void main(String[] args) { char my_temp; System.out.print("Displaying Alphabets from A to Z \n"); for(my_temp= 'A'; my_temp <= 'Z'; ++ my_temp) System.out.print(my_temp+ " "); } }
Output
Displaying Alphabets from A to Z 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
Example 2
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
public class Alphabets { public static void main(String[] args) { char my_temp; System.out.print("Displaying Alphabets from a to z \n"); for(my_temp = 'a'; my_temp <= 'z'; ++my_temp) System.out.print(my_temp + " "); } }
Output
Displaying Alphabets from a to z 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
Advertisements