# Print diamond pattern in C and Java

Write a C and Java program to print diamond pattern of stars. This post covers below patterns

##### Pattern 1: Diamond

*
*  *  *
*  *  *  *  *
*  *  *  *  *  *  *
*  *  *  *  *  *  *  *  *
*  *  *  *  *  *  *
*  *  *  *  *
*  *  *
*

The problem looks complex at first look but it can be easily solved by breaking it into sub-problems. If we take a closer look, the upper half is almost similar to Pyramid Pattern with n rows and lower half is similar to Inverted Pyramid Pattern with n-1 rows.

## Java

##### Pattern 2: Hollow Diamond

*  *  *  *  *  *  *  *  *  *
*  *  *  *        *  *  *  *
*  *  *              *  *  *
*  *                    *  *
*                          *
*  *                    *  *
*  *  *              *  *  *
*  *  *  *        *  *  *  *
*  *  *  *  *  *  *  *  *  *

## Java

##### Pattern 3: Left Half Diamond

*
*  *
*  *  *
*  *  *  *
*  *  *  *  *
*  *  *  *
*  *  *
*  *
*

Like Pattern 1, the problem can be easily divided into sub-problems. The upper half is similar to Right-angled Triangle Pattern with n rows and lower half is similar to Inverted Right-angled Triangle with n-1 rows.

## Java

##### Pattern 4: Right Half Diamond

*
*  *
*  *  *
*  *  *  *
*  *  *  *  *
*  *  *  *
*  *  *
*  *
*

Similarly, this pattern can be easily printed by breaking it into sub-patterns. The upper half is similar to Right-angled Triangle Pattern with n rows and lower half is similar to Inverted Right-angled Triangle with n-1 rows.

## Java

Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂

Get great deals at Amazon