For loop alphabet java – Java Program to Display Alphabets (A to Z and a-z) using loop

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:

  1. Take a character variable say 'ch'.
  2. Start a loop from ‘ch’ value ‘A’ to ‘ch’ value ‘Z’.
  3. As internally it is stored in ASCII code, So loop through 65 to 90.
  4. 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:

  1. Take a character variable say 'ch'.
  2. Start a loop from ‘ch’ value ‘a’ to ‘ch’ value ‘z’.
  3. As internally it is stored in ASCII code, So loop through 97 to 122.
  4. 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: