1. Hollow Rectangle Pattern

Hollow patterns are the combinations of star and spaces. So we have to think about the spaces while printing such patterns.
From observation only we can say that, it has 4 rows and 5 columns. In each rows, 1st and last column do have stars. And apart from the 1st and last row remaining rows have equal number of spaces leaving 1st and last column.
So the logic can be, just print the 1st and last star in each rows (they are reserved). We have to work other remaining stars in the middle(columns).
So while printing the remaining stars (columns), again just look the patterns, if it is 1st and last row then all remaining spaces are filled with stars. Other remaining rows have spaces instead of stars. So here we can use the if condition where if it is 1st and last row then print the stars else print the spaces.
so the code can be:

2. Character Pyramid pattern
It is a continuous pattern where each time the character is updated with its new character. so here, increment operator is used(++).


3. Triangular Pyramid

Here, the given pattern is the combination of stars and spaces. Here, we have taken two inner loops. One loop for printing spaces and another for printing stars.
From the pattern,
In the 1st row, there are 2 spaces, 2nd row has 1 space and last row has zero spaces. If we see logically then, in first row (if suppose n = 3), n-i = 3-1 = 2 space, in 2nd row, 3 – 2 = 1space, 3rd row, 3-3 = 0 space. so range can be from 1 to n-i for printing spaces.
we can analyze that, there are 3 rows and 5 columns. In 1st row, there is 1 star, in 2nd row, there are 3 stars and in last row there are 5 stars.
here, number of stars are in odd numbers, so we can start the loop from 1 to 2*i-1 for printing stars.

4. Diamond Pattern

here, if we see the pattern closely, then it can be divided into 2 triangular patterns, one is in upward and another is in downward direction. so the logic will be similar as of ques. 3.
