Author: admin

  • 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

  • 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
  • Hourglass Star Pattern in Java

    Hourglass Star Pattern in Java

    In this tutorial, we will write a java program to print sandglass star patterns. Before that, you may go through the following topic in java.

    The program below takes a user input for the number of rows needed and then in decreasing order of the first half is printed and then the increasing order of the second half of the sandglass is printed.

    This is an hourglass pattern program in java or you can say sandglass pattern program using a star.

    Input of row: 4  
    * * * *
     * * * 
      * * 
       *  
       * 
      * * 
     * * * 
    * * * *

    Hourglass Star 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 number of rows: ");
        rows = sc.nextInt();
    
        System.out.print("Output: \n\n");
        //upper half
        for (i = 1; i <= rows; i++)
        {
          for (k = 1; k <= i - 1; k++)
          {
            System.out.print("*" + " ");
          }
          for (j = 1; j <= rows - i + 1; j++)
          {
            System.out.print("*");
          }
          System.out.println();
        }
    
        //lower half
        for (i = rows - 1; i >= 1; i--)
        {
          for (k = 1; k <= i - 1; k++)
          {
            System.out.print(" ");
          }
          for (j = i; j <= rows; j++)
          {
            System.out.print("*" + " ");
          }
          System.out.println();
        }
      }
    }

    Output:

    Hourglass Star Pattern in Java

  • Hourglass Number Pattern in Java

    Hourglass Number Pattern in Java

    In this tutorial, we will write a java program to print sandglass number pattern. Before that, you may go through the following topic in java.

    The program below takes a user input for the number of rows needed and then in decreasing order of the first half is printed and then the increasing order of the second half of the sandglass is printed.

    This is an hourglass pattern program in java or you can say sandglass pattern program using number.


    Hourglass Number 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 number of rows: ");
        rows = sc.nextInt();
    
        //upper half
        for (i = 1; i <= rows; i++)
        {
          for (k = 1; k < i; k++)
            System.out.print(" ");
    
          for (j = i; j <= rows; j++)
            System.out.print(j + " ");
    
          System.out.println();
        }
    
        //lower half
        for (i = rows - 1; i >= 1; i--)
        {
          for (k = 1; k < i; k++)
            System.out.print(" ");
    
          for (j = i; j <= rows; j++)
            System.out.print(j + " ");
    
          System.out.println();
        }
      }
    }

    Output:

    Hourglass Number Pattern in Java

  • Mirror Image Triangular Number Pattern in Java

    Mirror Image Triangular Number Pattern in Java

    In this tutorial, we will write a program to print a triangle pattern in java where the pattern is repeated by dividing each row in two half just like a mirror. Before that, you may go through the following topic in java.

    Example:

    Input: 5
    Output:
         0
        101
       21012
      3210123
     432101234

    The program takes the user input for the number of rows and displays the result using the for loop in java. The program is a mirror triangle number pattern in java or you can say full pyramid of numbers with mirror image numbers.


    Program for triangular pattern

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

    Output:

    Enter the number of rows: 6
         0
        101
       21012
      3210123
     432101234
    54321012345

  • Right Triangle Pattern of Numbers in Java with Repeating Pattern (Mirror image)

    Right Triangle Pattern of Numbers in Java with Repeating Pattern (Mirror image)

    In this tutorial, we will write a program to print a triangle pattern in java where the pattern is repeated on each row and keep on increasing. Before that, you may go through the following topic in java.

    Example:

    Input: 5
    1
    1 2 1
    1 2 3 2 1
    1 2 3 4 3 2 1

    The program takes the user input for the number of rows and displays the result using the for loop in java. The program is mirror right angled triangle pattern with a repetition pattern or you can say half pyramid of numbers with a repetition pattern.


    Java Program to print the right triangle number pattern

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

    Output:

    Enter the number of rows: 5
    1
    1 2 1
    1 2 3 2 1
    1 2 3 4 3 2 1
    1 2 3 4 5 4 3 2 1

    1 2 3 4 5 6 5 4 3 2 1


  • Inverted Triangle Pattern in Java with Descending Order

    Inverted Triangle Pattern in Java with Descending Order

    In this tutorial, we will write a java program to print reverse right angled triangle of numbers with numbers in descending order. Before that, you may go through the following topic in java.

    The program takes the user input for the number of rows and displays the result using the for loop in java. The number is displayed by decreasing order until it becomes a single digit at the last.

    The program is an inverted right triangle number pattern in java or you can say half pyramid of numbers in decreasing order.


    Java program to print the right triangle pattern of Numbers

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

    Output:

    Enter the number of rows: 8
    8 7 6 5 4 3 2 1
    8 7 6 5 4 3 2
    8 7 6 5 4 3
    8 7 6 5 4
    8 7 6 5
    8 7 6
    8 7
    8


  • Triangle Pattern with Repeated Digits in Java

    Triangle Pattern with Repeated Digits in Java

    In this tutorial, we will write a program to print triangular number patterns in java where the digits are repeated on each row. Before that, you may go through the following topic in java.

    The program takes the user input for the number of rows and displays the result using the for loop in java. The program is right angled triangle pattern or you can say half pyramid of numbers with repetition of digits.


    Java program to print right triangle pattern with repeatation of digits

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

    Output:

    Enter the number of rows: 6
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5
    6 6 6 6 6 6