Tag: java alphabet pattern

  • Reverse Pyramid with Alphabet in Java

    Reverse Pyramid with Alphabet in Java

    In this tutorial, we will write a reverse alphabet triangle pattern in java. Before that, you may go through the following topic in java.

    The program takes a user input for the number of rows to be printed. Then the inverted alphabet pattern is displayed on the screen.


    Java Program to display the Reverse Pyramid pattern with Alphabet

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner scan = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = scan.nextInt();
    
        System.out.print("Output:\n");
        for (i = rows; i >= 1; i--)
        {
          for (j = 1; j <= rows - i; j++)
            System.out.print("  ");
    
          for (j = 1; j <= 2 *i - 1; j++)
          {
            if (j <= i)
              System.out.print((char)(char)(j + 64) + " ");
            else
              System.out.print((char)(char)(2 *i - j + 64) + " ");
          }
          System.out.println();
        }
      }
    }
    Enter the number of rows: 5
    Output:
    A B C D E D C B A
      A B C D C B A
        A B C B A
          A B A
            A

  • Alphabet Pyramid Pattern in Java: pattern 1

    Alphabet Pyramid Pattern in Java: pattern 1

    In this tutorial, we will write a Java program to display alphabet pyramid patterns. Before that, you may go through the following topic in java.

    We will look at pyramid patterns in java using alphabets/letters/characters.

    Pyramid triangle alphabet

    This is a mirror image pattern of letters in java.

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner scan = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = scan.nextInt();
    
        for (i = 1; i <= rows; i++)
        {
          for (j = 1; j <= rows - i; j++)
            System.out.print(" ");
    
          for (j = 1; j <= i; j++)
            System.out.print((char)(j + 64));
    
          for (j = i - 1; j >= 1; j--)
            System.out.print((char)(j + 64));
    
          System.out.println();
        }
      }
    }

    Enter the number of rows: 6
         A
        ABA
       ABCBA
      ABCDCBA
     ABCDEDCBA
    ABCDEFEDCBA
  • Top 10 Different Alphabet Pattern Programs in Java

    Top 10 Different Alphabet Pattern Programs in Java

    This post focuses on the various Java pattern program specifically Top 10 Different Alphabet Pattern Programs in Java. Patterns are one of the easiest ways to improve the coding skills for java. The frequent use loops can increase your skills and printing pattern in order. This article covers various Alphabet patterns. Other are:

    Let’s begin:

    Alphabet/Character Patterns in Java

    Pattern programs in java: Pattern 1

     A
     B B
     C C C
     D D D D
     E E E E E
     F F F F F F
     G G G G G G G
     H H H H H H H H

    Let us understand the code:

     //Pattern with alphabets
    
     public class Pattern1  
     {  
        public static void main(String[] args)  
        {  
            int count = 7;  
            for(int i = 0 ; i <= count  ; i++)  
            {  
             for(int j = 0 ; j <= i ; j++)  
             {  
              System.out.print(" "+(char)(65 + i));  
             }  
              System.out.println("");  
            }  
        }  
     }

    Pattern programs in java: Pattern 2

    Enter the number of rows: 5
    A
    A B
    A B C
    A B C D
    A B C D E
    import java.util.Scanner;
    public class Pattern2
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           // ASCII value of alphabet 'A'
            int alph = 65; 
            
            for (int i=0; i< rows; i++)
            {
                for (int j=0; j<=i; j++)
                {
                  System.out.print((char) (alph+j) + " ");
                }
                System.out.println();
            }
             
            sc.close();
        }
    }

    Pattern programs in java: Pattern 3

    Enter the number of rows: 5
    A B C D E F 
    A B C D E 
    A B C D 
    A B C 
    A B 
    A 
    A 
    A B 
    A B C 
    A B C D 
    A B C D E 
    A B C D E F
    import java.util.Scanner;
    public class Pattern3
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           for (int i = 5; i >= 0; i--)
           {
            // ASCII value of alphabet 'A'
            int alph = 65;
            
            for (int j = 0; j <= i; j++)
                System.out.print((char) (alph + j) + " ");
            
            System.out.println();
           }
        
          for (int i = 0; i<= 5; i++)
          {
           int alph = 65;
           for (int j = 0; j <= i; j++)
              System.out.print((char) (alph + j) + " ");
       
           System.out.println();
          }
             
        sc.close();
      }
    }

    Pattern programs in java: Pattern 4

    Enter the number of rows: 5
    E
    E D
    E D C
    E D C B
    E D C B A
    import java.util.Scanner;
    public class Pattern4
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           // ASCII value of alphabet 'A'
           int alphabet = 65; 
            
            for (int i=rows-1; i>=0 ; i--)
            {
              for (int j=rows-1; j>=i; j--)
              {
                System.out.print((char) (alphabet+j) + " ");
              }
             System.out.println();
            }
             
        sc.close();
      }
    }

    Pattern programs in java: Pattern 5

    Full pyramid character pattern in Java.

    Enter the number of rows: 5
          A
         A B
        A B C
       A B C D
      A B C D E
    import java.util.Scanner;
    public class Pattern5
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           // ASCII value of alphabet 'A'
           int alphabet = 65; 
            
           for (int i= 0; i<= rows-1 ; i++)
            {
                for (int j=rows-1; j>i; j--)
                {
                     System.out.print(" ");
                }
                for (int k=0; k<=i; k++)
                {
                     System.out.print((char) (alphabet+k) + " ");
                }
                System.out.println();
            }
             
        sc.close();
      }
    }

    Pattern programs in java: Pattern 6

    Inverted pyramid pattern of alphabets in java.

    Enter the number of rows: 5
       A B C D E
        A B C D
         A B C
          A B
           A
    import java.util.Scanner;
    
    public class Pattern6
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           // ASCII value of alphabet 'A'
           int alphabet = 65; 
            
           for (int i= 0; i<= rows-1 ; i++)
            {
                for (int j=0; j<=i; j++)
                {
                    System.out.print(" ");
                }
                for (int k=0; k<=rows-1-i; k++)
                {
                  System.out.print((char) (alphabet + k) + " ");
                }
                System.out.println();
            }
             
        sc.close();
      }
    }

    Pattern programs in java: Pattern 7

    Enter the number of rows: 6
    A B C D E F 
     B C D E F 
      C D E F 
       D E F 
        E F 
         F 
         F 
        E F 
       D E F 
      C D E F 
     B C D E F 
    A B C D E F 
    import java.util.Scanner;
    
    public class Pattern7
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           // ASCII value of alphabet 'A'
           int alphabet = 65; 
            
           for (int i= 0; i<= rows-1 ; i++)
           {
            for (int j=0; j<i; j++)
            {
              System.out.print(" ");
            }
            for (int k=i; k<=rows-1; k++)
            {
              System.out.print((char) (alphabet + k) + " ");
            }
            System.out.println("");
           }
            
            for (int i= rows-1; i>= 0; i--)
            {
             for (int j=0; j<i; j++)
             {
               System.out.print(" ");
             }
             for (int k=i; k<=rows-1; k++)
             {
               System.out.print((char) (alphabet + k) + " ");
             }
            System.out.println("");
            }
             
        sc.close();
      }
    }

    Pattern programs in java: Pattern 8

    Enter the number of rows: 5
    A  
    A B  
    A B C 
    A B C D  
    A B C D E 
    A B C D 
    A B C 
    A B  
    A  
    import java.util.Scanner;
    public class Pattern8
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           // ASCII value of alphabet 'A'
           int alphabet = 65; 
            
           for (int i= 0; i<= rows-1 ; i++)
            {
             for (int j=0; j<=i; j++)
             {
                System.out.print((char) (alphabet + j)+ " ");
             }
            System.out.println("");
            }
            for (int i=rows-1; i>=0; i--)
            {
             for(int j=0; j <= i-1;j++)
             {
                System.out.print((char) (alphabet + j)+ " ");
             }
            System.out.println("");
            }
             
        sc.close();
      }
    }

    Pattern programs in java: Pattern 9

    Enter the number of rows: 5
         A
        BB
       CCC
      DDDD
     EEEEE
    FFFFFF
    import java.util.Scanner;
    public class Pattern9
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           // ASCII value of alphabet 'A'
           int alphabet = 65; 
            
           for (int i= 0; i<= rows; i++)
            {
             for (int j=1; j<=rows-i; j++)
             {
                System.out.print(" ");
             }
             
             for (int k=0;k<=i;k++)
             {
                System.out.print((char) (i+alphabet));
             }  
                System.out.println("");
            }
             
        sc.close();
      }
    }

    Pattern programs in java: Pattern 10

    import java.util.Scanner;
    public class Pattern10
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter the number of rows: ");
            int rows = sc.nextInt();
           
           // ASCII value of alphabet 'A'
           int alphabet = 65; 
            
           for (int i= 1; i<= rows ; i++)
            {
             int count = rows -1;
             int temp = i;
             
             for (int j=1; j<=i; j++)
             {
                System.out.printf("%4c", (char)temp + alphabet-1);
                temp = temp + count;
                count--;
             }
            System.out.println("");
            }
             
        sc.close();
      }
    }