Open In App

Java Pattern Programs - Learn How to Print Pattern in Java

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
48 Likes
Like
Report

In many Java interviews Star, number, and character patterns are the most asked Java Pattern Programs to check your logical and coding skills. Pattern programs in Java help you to sharpen your looping concepts (especially for loop) and problem-solving skills in Java. If you are looking for a place to get all the Java pattern programs with solutions, stop your search here.

Here, we have compiled a top pattern exercises on Java.

Prerequisite: Remember that to learn pattern programs, you must know Java Loops (for, while, do-while) and basic syntax.

Patterns Programs in Java
Patterns Programs in Java

Java Pattern Programs

Here, you will find the top 25 Java pattern programs with their proper code and explanation. 

All Pattern Programs in Java are mentioned below:

1. Square Hollow Pattern

This program prints a square where the border is filled with stars (*), and the inside is hollow (filled with spaces).


Output
******
*    *
*    *
*    *
*    *
******


2. Number Triangle Pattern

Prints a right-angled triangle with numbers in increasing row order, aligned to the right.


Output
     1 
    2 2 
   3 3 3 
  4 4 4 4 
 5 5 5 5 5 
6 6 6 6 6 6 


3. Number-Increasing Pyramid Pattern 

Prints a pyramid where each row contains numbers from 1 to the row number.


Output
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 


4. Number-Increasing Reverse Pyramid Pattern

This is a reverse pyramid where each row starts from 1 and ends at the row count, in decreasing number of elements.


Output
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 


5. Number-Changing Pyramid Pattern

Prints a pyramid where numbers increase continuously from top to bottom.


Output
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21 


6. Zero-One Triangle Pattern

Prints a triangle where each number alternates between 1 and 0 based on the position.


Output
1 
0 1 
1 0 1 
0 1 0 1 
1 0 1 0 1 
0 1 0 1 0 1 


7. Palindrome Triangle Pattern

Prints a triangle with mirrored numbers forming a palindrome on each row.


Output
          1 
        2 1 2 
      3 2 1 2 3 
    4 3 2 1 2 3 4 
  5 4 3 2 1 2 3 4 5 
6 5 4 3 2 1 2 3 4 5 6 


8. Rhombus Pattern

Prints a rhombus (tilted square) made of stars, shifted by spaces.


Output
     ******
    ******
   ******
  ******
 ******
******


9. Diamond Star Pattern

Prints a diamond shape made of stars.


Output
     *
    ***
   *****
  *******
 *********
***********
 *********
  *******
   *****
    ***
     *


10. Butterfly Star Pattern

Prints a butterfly-shaped pattern using stars (*).


Output
*          *
**        **
***      ***
****    ****
*****  *****
************
************
*****  *****
****    ****
***      ***
**        **
*          *


11. Square Fill Pattern

This program prints a filled square of stars (*) with n+1 rows and columns.


Output
******
******
******
******
******
******


12. Right Half Pyramid Pattern

This creates a right-angled triangle aligned to the left using stars.


Output
*
**
***
****
*****
******


13. Reverse Right Half Pyramid Pattern

This prints a right-aligned triangle but in reverse top to bottom.


Output
******
*****
****
***
**
*


14. Left Half Pyramid Pattern

This pattern aligns a triangle to the right by adding spaces before stars.


Output
     *
    **
   ***
  ****
 *****
******


15. Reverse Left Half Pyramid Pattern

This prints a left pyramid in reverse, starting from full-width and decreasing.


Output
******
 *****
  ****
   ***
    **
     *


16. Triangle Star Pattern

This prints an equilateral triangle where stars are spaced apart.


Output
     * 
    * * 
   * * * 
  * * * * 
 * * * * * 
* * * * * * 


17. Reverse Number Triangle Pattern

A reverse right-aligned triangle with ascending numbers from i to n.


Output
1 2 3 4 5 6 
 2 3 4 5 6 
  3 4 5 6 
   4 5 6 
    5 6 
     6 


18. Mirror Image Triangle Pattern

This creates a mirrored triangle with numbers, forming a diamond-like shape.


Output
1 2 3 4 5 6 
 2 3 4 5 6 
  3 4 5 6 
   4 5 6 
    5 6 
     6 
    5 6 
   4 5 6 
  3 4 5 6 
 2 3 4 5 6 
1 2 3 4 5 6 


19. Hollow Triangle Pattern

This prints a hollow equilateral triangle using stars with only the boundary.


Output
     *
    * *
   *   *
  *     *
 *       *
***********


20. Hollow Reverse Triangle Pattern

Prints an inverted hollow triangle with stars only at boundaries and top row.


Output
***********
 *       *
  *     *
   *   *
    * *
     *


21. Hollow Diamond Pyramid

Prints a symmetrical hollow diamond made of stars, with spaces in the middle and stars only at the borders.


Output
     *
    * *
   *   *
  *     *
 *       *
*         *
 *       *
  *     *
   *   *
    * *
     *


22. Hollow Hourglass Pattern

Displays a hollow hourglass using stars, where only boundary stars are visible in a symmetric hourglass shape.


Output
* * * * * * 
 *       * 
  *     * 
   *   * 
    * * 
     * 
    * * 
   *   * 
  *     * 
 *       * 
* * * * * * 


23. Pascal's Triangle

Generates Pascal’s Triangle with proper alignment, showing binomial coefficients for each row.


Output
    1 
   1 1 
  1 2 1 
 1 3 3 1 


24. Right Pascal’s Triangle

Forms a right-angled triangle pointing upward and downward, creating a right Pascal’s triangle shape.


Output
* 
* * 
* * * 
* * * * 
* * * 
* * 
* 


25. K Pattern

Prints an inverted and then upright right half pyramid (like K shaped), forming a symmetrical star pattern.


Output
******
*****
****
***
**
*
**
***
****
*****
******

Conclusion

Java pattern programs are a great way to learn and practice coding skills. They help you understand loops, nested loops, and how to think logically to solve problems. Whether you are a beginner or an experienced programmer, practicing pattern programs can improve your Java skills. So, keep coding, experimenting with different patterns, and enjoy the learning process


Practice Tags :

Similar Reads