Display Hollow Inverted Pyramid pattern in C language. Display Hollow Inverted Pyramid pattern in Java language. Display hollow diamond shape in C language. Display Hollow diamond shape in Java language. Display diamond shape in C language. In the hollow diamond pattern , the first and last row contains only a star, and the rest of the rows contains two stars. To print the hollow diamond pattern as shown in the following figure , we will break the pattern into two sections i.
Also, we will implement the logic for the upper and lower sections, separately. The logic is applied to all patterns discussed in this section. In the above program, we observe that to print the lower half pattern, we have done only changes in the first for loop, the rest of the code is the same. To print the following hollow diamond pattern, we will divide the pattern into two sections i.
The upper section contains the first five rows and the lower section contains the last five rows of the diamond pattern. In the next row 2 nd , there are two spaces. We have to calculate space. In the upper section, we observe that the space is going doubled and in the lower section space is decreasing by 2.
Suppose, we have to calculate space for the third row. In the following program, we have used the variable i for rows, j for columns, and k for spaces. JavaTpoint offers too many high quality services.
Mail us on [email protected] , to get more information about given services. Please mail your requirement at [email protected] Duration: 1 week to 2 week. Java Training Java Tutorial. Abstract class Interface Abstract vs Interface. You can try with any other number too. In this program, first the num variable is declared and initialized. That's it. Rest of the codes are similar to second program. This program is almost similar to previous, as in place of num of int type, to print diamond of numbers, I've used alphabet of char type, to print diamond of alphabet.
This is the last program of this article, created to allow user to enter the character to form the diamond using that character. Java Program to Print Diamond Pattern.
0コメント