Java program to print all alphabets

Sharing is healthy !!

Hey guys!! Welcome to flower brackets blog. In this post we are going to learn java program to print all alphabets.

Here in the below example we are going to show you three methods to print alphabet in java.

Java program to print all alphabets

Java program to print all alphabets: using for loop

Let’s learn java loop through alphabet using for loop alphabet java,

public class JavaPrintAlphabet
{
   public static void main(String[] args)
   {
      System.out.println("Printing the Alphabets from a to z : "); 
      char alpha;
 
      for(alpha = 'a'; alpha <= 'z'; alpha++)
         System.out.println(alpha);
   }
}

Output:

Printing the 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


Method one: using while loop

public class JavaAlphabet
{
   public static void main(String[] args)
   {
      System.out.println("Printing the Alphabets from a to z : "); 
      char alpha = 'a';
 
      while(alpha <= 'z')
      {
         System.out.println(alpha);
         alpha++;
      }
   }
}

Output:

Printing the 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


Method two : using do while loop

public class AlphabetInJava
{
   public static void main(String[] args)
   {
      System.out.println("Printing the Alphabets from a to z : "); 
      char alpha = 'a';
 
      do
      {
         System.out.println(alpha);
         alpha++;
 
      } while(alpha <= 'z');
   }
}

Output:

Printing the 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


However, above java example to print all alphabets can also be used to print few alphabets, that is, from alphabet ‘a’ to alphabet ‘m’.

Also Read – Java Program To Print Floyd Triangle

See an example below,

public class JavaPrintAlphabet
{
   public static void main(String[] args)
   {
      System.out.println("Printing the Alphabets from a to m : ");
      char alpha = 'a';
 
      do
      { 
         System.out.println(alpha);
         alpha++;
      } while(alpha <= 'm');
   }
}

Output:

Printing the Alphabets from a to m: a b c d e f g h i j k l m


Also in the above java example to print all alphabets, alphabets can be printed in uppercase letters(above example output is in lowercase).

Let’s see an example,

public class JavaPrintAlphabet
{
   public static void main(String[] args)
   {
      System.out.println("Printing the alphabets from A to Z : "); 
      char alpha;
 
      for(alpha = 'A'; alpha <= 'Z'; alpha++)
      {
         System.out.println(alpha);
      } 
   }
}

Output:

Printing the 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


conclusion

That’s it guys. Today we learnt java uppercase to lowercase and for loop with characters.

I hope you guys have understood printing alphabet in java. You can subscribe to my blog flower brackets if you haven’t already.

Do share this post if you like.

Sharing is healthy !!

You May Also Like