For loop alphabet java: Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners tutorial.
Program to Display Alphabets (A to Z) using loop
In this article we will see how by using loop we can display alphabets from A to Z using loop.
We will see two different examples for displaying capital letters (A-Z) and displaying small letters (a-z).
Let’s see one by one.
Example-1 : Using for loop displaying from A-Z
By using for loop we can display from A to Z.
See the below approach to know how to do it.
Approach:
- Take a character variable say
'ch'
. - Start a loop from ‘ch’ value ‘A’ to ‘ch’ value ‘Z’.
- As internally it is stored in ASCII code, So loop through 65 to 90.
- This will print one by one character.
Program:
class Alphabet { public static void main(String[] args) { // character variable taken 'ch' char ch; // for loop starts from A to Z for(ch = 'A'; ch <= 'Z'; ch++) // printing one by one character System.out.print(ch + " "); } }
Output:
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 : Using for loop displaying from a-z
By using for loop we can display from a to z.
See the below approach to know how to do it.
Approach:
- Take a character variable say
'ch'
. - Start a loop from ‘ch’ value ‘a’ to ‘ch’ value ‘z’.
- As internally it is stored in ASCII code, So loop through 97 to 122.
- This will print one by one character.
Program:
class Alphabet { public static void main(String[] args) { // character varible'ch' char ch; // looping from 'a' to 'z' for(ch = 'a'; ch <= 'z'; ch++) { // prinitng one by one character System.out.print(ch + " "); } } }
Output:
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
Get started with learning the programming language Java from beginner to experienced level by referring to our collection of Java Programs with Source Code and become a pro in the subject.
Related Java Decision Making and Loop Programs:
- Java Program to Check Leap Year
- Java Program to Check Whether a Number is Positive or Negative
- Java Program to Check Whether a Character is Alphabet or Not
- Java Program to Calculate the Sum of Natural Numbers
- Java Program to Find Factorial of a Number
- Java Program to Generate Multiplication Table
- Java Program to Find GCD of two Numbers
- Java Program to Find LCM of two Numbers
- Java Program to Count Number of Digits in an Integer
- Java Program to Check Palindrome
- Java Program to Check Whether a Number is Prime or Not
- Java Program to Check Armstrong Number
- Java Program to Display Armstrong Number Between Two Intervals
- Java Program to Make a Simple Calculator Using switch…case
- Java Program to Sort Elements in Lexicographical Order (Dictionary Order)