Printing alphabets java

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

printing alphabets java

Here in the below java program to print alphabets we are going to show you three methods. To begin with let’s see java program to display characters in lower case,

Printing alphabets java : using for loop

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

Output:

Printing 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


Java program to display characters from A to Z using while loop

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

Output:

Printing 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


Java program to display characters from A to Z using do while loop

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

Output:

Printing 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

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

Output:

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


Meanwhile, we can also write java program to display all alphabets from A to Z in uppercase,

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

Output:

Printing 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

Related Posts