Tag: java alphabet pattern

  • Alphabet Pyramid Pattern in Java: pattern 3

    Alphabet Pyramid Pattern in Java: pattern 3

    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.

    Trianglular alphabet pattern

    This is a program the pattern is that the alphabet starts with A and at every increment of the row there is an increment in alphabet such as A, AB, ABC, and so on.

    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 = 1; i <= rows; i++)
        {
          for (j = 1; j <= rows - i; j++)
            System.out.print(" ");
    
          for (j = 1; j <= i; j++)
            System.out.print((char)(char)(j + 64) + " ");
    
          System.out.println();
        }
      }
    }
    Enter the number of rows: 7
    Output:
          A
         A B
        A B C
       A B C D
      A B C D E
     A B C D E F
    A B C D E F G

  • Alphabet Pyramid Pattern in Java: pattern 2

    Alphabet Pyramid Pattern in Java: pattern 2

    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.

    Trianglular alphabet pattern

    This is a program the right half and left half remain exactly the same on each row forming a triangular pyramid.

    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\n");
        for (i = 1; i <= rows; i++)
        {
          for (j = 1; j <= rows - i; j++)
            System.out.print(" ");
    
          //left half
          for (j = i; j > 0; j--)
            System.out.print((char)(j + 64));
    
          //right half
          for (j = 2; j <= i; j++)
            System.out.print((char)(j + 64));
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the number of rows: 8
    Output:
         
           A
          BAB
         CBABC
        DCBABCD 
       EDCBABCDE
      FEDCBABCDEF
     GFEDCBABCDEFG
    HGFEDCBABCDEFGH

  • Half Repeated Character Pattern in Java

    Half Repeated Character Pattern in Java

    In this tutorial, we will go through alphabet pattern programs in java programming. Before that, you may go through the following topic in java.


    Half Repeated Character Pattern in Java

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

    Output:

    Enter the no. of rows: 5
    ABCDEF
     BCDEF
      CDEF
       DEF
        EF
         F
         F
        EF
       DEF
      CDEF
     BCDEF
    ABCDEF

  • 2 Different Alphabet Patterns in Java (half hourglass)

    2 Different Alphabet Patterns in Java (half hourglass)

    In this tutorial, we will go through two different alphabet pattern programs in java programming. Before that, you may go through the following topic in java.


    2 different Alphabet pattern program in Java

    Both of the programs below take the number of rows as the user input and using for loop it prints the desired output.

    Pattern 1:

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the no. of rows: ");
        rows = sc.nextInt();
    
        //upper part
        for (i = rows; i >= 0; i--)
        {
          int character = 65;
          for (j = 0; j <= i; j++)
            System.out.print((char)(character + j) + " ");
    
          System.out.println();
        }
        //lower part
        for (i = 0; i <= rows; i++)
        {
          int character = 65;
          for (j = 0; j <= i; j++)
            System.out.print((char)(character + j) + " ");
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the no. 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


    Pattern 2:

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the no. of rows: ");
        rows = sc.nextInt();
    
        //upper part
        for (i = rows; i >= 0; i--)
        {
          int character = 65;
          for (j = i; j >= 0; j--)
            System.out.print((char)(character + j) + " ");
    
          System.out.println();
        }
        //lower part
        for (i = 0; i <= rows; i++)
        {
          int character = 65;
          for (j = i; j >= 0; j--)
            System.out.print((char)(character + j) + " ");
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the no. of rows: 5
    F E D C B A
    E D C B A
    D C B A
    C B A
    B A
    A
    A
    B A
    C B A
    D C B A
    E D C B A
    F E D C B A


  • 2 Different Alphabet Patterns in Java (sideways triangle)

    2 Different Alphabet Patterns in Java (sideways triangle)

    In this tutorial, we will go through two different alphabet pattern programs in java programming. Before that, you may go through the following topic in java.


    2 different Alphabet pattern program in Java

    Both of the programs below take the number of rows as the user input and using for loop it prints the desired output.

    The patterns include the sideways triangle or the pyramid with different alphabet patterns, also the half hourglass patterns containing different patterns.

    Pattern 1:

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

    Output:

    Enter the no. of rows: 5
    A
    A B
    A B C
    A B C D
    A B C D E
    A B C D E F
    A B C D E
    A B C D
    A B C
    A B
    A


    Pattern 2:

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        int character = 65;
        int count = 1;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the no. of rows: ");
        rows = sc.nextInt();
    
        for (i = 1; i <= rows / 2 + 1; i++)
        {
          for (j = 1; j <= i; j++)
            System.out.print((char)(character + (count *j) - 1) + " ");
    
          System.out.println();
          count++;
        }
    
        for (i = 1; i <= rows / 2; i++)
        {
          for (j = 1; j <= rows / 2 + 1 - i; j++)
            System.out.print((char)(character + (count *j) - 1) + " ");
    
          System.out.println();
          count++;
        }
      }
    }

    Output:

    Enter the no. of rows: 9
    A
    B D
    C F I
    D H L P
    E J O T Y
    F L R X
    G N U
    H P
    I


  • Alphabet Pattern Programs in Java (Diamond Shape)

    Alphabet Pattern Programs in Java (Diamond Shape)

    In this tutorial, we will go through different alphabet patterns in java. Before that, you may go through the following topic in java.

    Both of the programs below take the user input for the number of rows to be printed for the alphabet pattern in java for the diamond shape.


    Alphabet diamond pattern in java

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j, k;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the no. of rows: ");
        rows = sc.nextInt();
    
        System.out.print("Diamond Shape Pattern: \n\n");
        for (i = 0; i <= rows; i++)
        {
          int ch = 65;
          for (j = rows; j >= i; j--)
          {
            System.out.print(" ");
          }
          for (k = 0; k <= i; k++)
          {
            System.out.print((char)(ch + k) + " ");
          }
          System.out.println();
        }
    
        for (i = 0; i <= rows; i++)
        {
          int ch = 65;
          for (j = -1; j <= i; j++)
          {
            System.out.print(" ");
          }
          for (k = 0; k <= (rows - 1) - i; k++)
          {
            System.out.print((char)(ch + k) + " ");
          }
          System.out.println();
        }
      }
    }

    Output:

    Alphabet diamond pattern in java

    Hollow Diamond Alphabet Pattern in java

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        int ch = 65;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the no. of rows: ");
        rows = sc.nextInt();
    
        System.out.print("Diamond Shape Pattern: \n\n");
    
        //Upper part of diamond
        for (i = 1; i <= rows; i++)
        {
          for (j = rows; j > i; j--)
            System.out.print(" ");
    
          System.out.print((char) ch++);
    
          for (j = 1; j < (i - 1) *2; j++)
            System.out.print(" ");
    
          if (i == 1)
            System.out.print("\n");
          else
            System.out.print((char) ch++ + "\n");
        }
    
        //lower part of diamond
        ch = 65;
        for (i = rows - 1; i >= 1; i--)
        {
          for (j = rows; j > i; j--)
            System.out.print(" ");
    
          System.out.print((char) ch++);
    
          for (j = 1; j < (i - 1) *2; j++)
            System.out.print(" ");
    
          if (i == 1)
            System.out.print("\n");
          else
            System.out.print((char) ch++ + "\n");
        }
      }
    }

    Output:

    Hollow Diamond Alphabet Pattern in java

  • Right Angle Triangle Character Pattern in Java: Pattern 1

    Right Angle Triangle Character Pattern in Java: Pattern 1

    In this tutorial, we will write a program to display a right-angle triangle pattern in java using the alphabet. Before that, you may go through the following topic in java.

    The program below takes the user input from the user for the number of rows and display the right triangle character pattern in various character orders.

    Right angled triangle pattern

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

    Output:

    Enter the number of rows: 6
    Output:
    A
    B B
    C C C
    D D D D
    E E E E E
    F F F F F F


  • Inverted Right Triangle Alphabet Pattern in Java: Pattern 1

    Inverted Right Triangle Alphabet Pattern in Java: Pattern 1

    In this tutorial, we will write a java program to display the reverse right triangle pattern using the alphabet. These are character pattern programs in java. Before that, you may go through the following topic in java.

    The programs below take the user input from the user for the number of rows and display the reverse right triangle character pattern in various character orders.

    This program can also be called the inverted half pyramid in java or Floyd’s triangle alphabet pattern in java.

    Reverse right angled triangle pattern

    In this program, the decrement of the Alphabet starts from the right corner of the pattern.

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

    Output:

    Enter the number of rows: 6
    Output:


    ABCDEF
    ABCDE
    ABCD
    ABC
    AB
    A


  • Similar Alphabet Pyramid Pattern in Java

    Similar Alphabet Pyramid Pattern in Java

    In this tutorial, we will write an alphabet triangular pattern in java where the characters or letters are every row have the same alphabet. Before that, you may go through the following topic in java.

    Example:

    Rows Input: 5
    Output:
           A
          B B
         C C C
        D D D D
       E E E E E
    

    Alphabet Pyramid Pattern 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();
    
        System.out.print("Output:\n");
        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)(char)(i + 64) + " ");
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the number of rows: 8
    Output:
           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

  • Java Program to print Half Pyramid using Alphabets in Increasing order

    Java Program to print Half Pyramid using Alphabets in Increasing order

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

    Example:

    Rows Input: 5
    Output:
    A
    A B
    A B C
    A B C D
    A B C D E

    This program is also known as right-angled triangle patterns using the alphabet in java as the right angle is formed on the right side of the pattern.


    Java Program to print Half Pyramid using Alphabets

    The program takes a user input for the number of rows to be displayed on the screen. The Alphabet starts from A and increases at every row such as A, Ab, ABC, and so on.

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

    Output:

    Enter the number of rows: 7
    Output:
    A
    A B
    A B C
    A B C D
    A B C D E
    A B C D E F
    A B C D E F G