# Crown Pattern in Java

The pattern programs are usually asked in interviews to check the logic implementation and loop concepts. In the previous section, we have discussed the various patterns like, triangle, tree, star, etc. In this section, we will learn how to print pattern of crown through a Java program using different logics.

We have divided the Crown Pattern in two sections. The first section contains the first five rows of the crown. The second section contains the last two rows of the crown, as we have shown in the following figure.

### Approach

• Read total number of rows from the user and store it in an integer variable named row.
• Calculate height (h) of the crown by using the formula (row -1)/2.
• Define two for loops, first outer for loop and second inner for loop.
• Use first for loop to print the row value and a star for each row.
• Use first inner for loop to print column value i.e., star according to the following condition:
if (c == 0 || c == h || c == row - 1) and (r == h- 1)and
if ((c < r || c > h - r) &&(c < h + r || c >= row - r)), else print the spaces .
• After that print the star (*) symbol according to loop.

Let's implement the above logic in a Java program.

CrownPattern.java

Output:

Let's see another logic.

CrownPatternExample2.java

Output:

In the following program, we can enter number of rows and character that we want to print.

CrownPatternExample3.java

Output: