{"id":159,"date":"2024-09-03T09:10:19","date_gmt":"2024-09-03T09:10:19","guid":{"rendered":"https:\/\/itvedant.com\/blog\/?p=159"},"modified":"2025-06-27T14:30:31","modified_gmt":"2025-06-27T09:00:31","slug":"hollow-pyramid-pattern-in-java","status":"publish","type":"post","link":"https:\/\/www.itvedant.com\/blog\/hollow-pyramid-pattern-in-java\/","title":{"rendered":"Hollow Pyramid Pattern in Java"},"content":{"rendered":"\n<p>A hollow pyramid pattern is a triangular design in which only the outline is visible, and the interior part of the pattern is empty. In programming, printing Characters\/Numbers\/Special Symbols in a particular pattern that forms a shape&#8217;s outline but leaves its interior empty is commonly known as hollow patterns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why is it Important to Learn the Hollow Pyramid Pattern Program?<\/h2>\n\n\n\n<p>The hollow pattern program will help you better understand nested loop concepts and conditional statements while improving your problem-solving and logical thinking.<\/p>\n\n\n\n<p>It allows programmers to experiment with various styles while working with graphics-based applications. Learning different patterns allows architects to experiment with different architectural layouts and configurations.<\/p>\n\n\n\n<p>Pattern programs, including hollow pyramid pattern programs, are common questions in technical interviews. Practicing these can help you prepare for coding interviews<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The concept of hollow patterns is frequently used for real-world applications such as<br>1. Image Processing:<\/h3>\n\n\n\n<p>Pattern programs can detect objects in images by comparing the pattern to the pixels. It can also be used to segment images based on a specific pattern.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Game Development:<\/h3>\n\n\n\n<p>The Pattern program can create graphics and visual elements for games, such as menus, buttons, options, dialogue boxes, etc<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. 3D Model:<\/h3>\n\n\n\n<p>Pattern programs can generate 3D mesh models with hollow interiors. It allows you to print objects with resonating sections.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Geographic Information System:<\/h3>\n\n\n\n<p>The Pattern program can be used to create maps and analyse spatial data.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Create a Hollow Pyramid Pattern in Java?<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Hollow Pyramid Pattern Using Star in Java<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">i. Code:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public class HollowPyramidPattern {\n\n\u00a0\u00a0\u00a0\u00a0public static void main(String&#91;] args) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int rows = 6;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(\"Pyramid Pattern of Stars by Itvedant\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int i, j, k;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (i = 1; i &lt;= rows; i++) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (j = 1; j &lt;= rows - i; j++) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.print(\" \");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (i == 1 || i == rows) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (k = 1; k &lt;= (i * 2) - 1; k++) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.print(\"*\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (k = 1; k &lt;= (i * 2) - 1; k++) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (k == 1 || k == i * 2 - 1) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.print(\"*\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.print(\" \");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println();\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0}\n\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">ii. Output:<\/h4>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXeGx9akZh3_m_m5sFIf1hBFyfbwUH6PqIllsmew3Chm_qk-C6_bmxtfVAs5SkvjY0nXUiqHOTDKjcdF1KEUTO0WyP1oXP_YEIZt7ddeVbAdZCg-XmfGcX4F9c44oe_hCSoT5NXFNgeuXYQHmpTdidCejRY?key=fz8AD9TjJ0w-bpz1KzLbmg\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">iii. Explanation:<\/h4>\n\n\n\n<p>Let\u2019s understand the Hollow Pattern Program.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>&nbsp;<\/td><td><strong>j=1<\/strong><\/td><td><strong>j=2<\/strong><\/td><td><strong>j=3<\/strong><\/td><td><strong>j=4<\/strong><\/td><td><strong>j=5<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=1<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=2<\/strong><\/td><td>&nbsp;<\/td><td><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=3<\/strong><\/td><td>&nbsp;<\/td><td><\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=4<\/strong><\/td><td>&nbsp;<\/td><td><\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=5<\/strong><\/td><td><\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=6<\/strong><\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>As it is seen in above Fig. there are 6 rows and 11 Columns where we have to print the hollow pattern.<\/p>\n\n\n\n<p>The code to print hollow patterns is divided into 3 parts i.e. Part 1: space before asterisk marks, part 2: asterisk mark itself and part 3: space and asterisk mark. To jump from one row to another row, the outer \u201cfor\u201d loop with the iterator variable \u201ci\u201d is considered. So, all three parts of the code will be executed in each row before we jump to the next row.<\/p>\n\n\n\n<p>Firstly, we will understand how to add spaces before a pattern starts. We are considering the nested for loop with the iterator variable \u201cj\u201d to iterate over the column part where space is supposed to be printed. Now let&#8217;s analyse the relation between the iterator variables \u201ci\u201d and \u201cj\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>For i=<\/strong><\/td><td><strong>j start<\/strong><\/td><td><strong>j end (i.e. total no.of spaces printed in that row)<\/strong><\/td><td><strong>Relation between the Current value of i and j end value<\/strong><\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>5<\/td><td>j end (5) = 6 \u2013 current value of i (1)<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>4<\/td><td>j end (4) = 6 \u2013 current value of i (2)<\/td><\/tr><tr><td>3<\/td><td>1<\/td><td>3<\/td><td>j end (3) = 6 \u2013 current value of i (3)<\/td><\/tr><tr><td>4<\/td><td>1<\/td><td>2<\/td><td>j end (2) = 6 \u2013 current value of i (4)<\/td><\/tr><tr><td>5<\/td><td>1<\/td><td>1<\/td><td>j end (1) = 6 \u2013 current value of i (5)<\/td><\/tr><tr><td>6<\/td><td>1<\/td><td>0<\/td><td>j end (0) = 6 \u2013 current value of i (6)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The above table shows that the starting value of \u201cj\u201d is always 1, but the ending value of the j iterator variable or space is always different. However, there is a relationship between the current value of \u201ci\u201d and the ending value of \u201cj\u201d, as shown in the table above.<\/p>\n\n\n\n<p>The ending value of \u201cj\u201d always equals the total rows &#8211; the current value of \u201ci\u201d. Considering the same, an inner for loop is designed, with the ending value of \u201cj\u201d as j = rows &#8211; i.<\/p>\n\n\n\n<p>Now, let\u2019s understand the second part of the pattern which is printing asterisk marks on the first and last line. For printing asterisk marks and space between the pattern iterator variable k is considered.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>&nbsp;<\/strong><strong>i=1<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><strong>k=1<\/strong>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=2<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=3<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=4<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=5<\/strong><\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=6<\/strong><\/td><td>*<strong>k=1<\/strong><\/td><td>*<strong>k=2<\/strong><\/td><td>*<strong>k=3<\/strong><\/td><td>*<strong>k=4<\/strong><\/td><td>*<strong>k=5<\/strong><\/td><td>*<strong>k=6<\/strong><\/td><td>*<strong>k=7<\/strong><\/td><td>*<strong>k=8<\/strong><\/td><td>*<strong>k=9<\/strong><\/td><td>*<strong>k=10<\/strong><\/td><td>*<strong>k=11<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>As seen in the above figure when the value of i=1 at that time only 1 asterisk (*) is printed and when the value of i=6, the number of asterisks is 11 so, considering the same starting value of \u201ck\u201d will be 1 for i=1 and i=6 and the ending condition of k will k&lt;=(i*2)-1 which matches the number of asterisk marks that are printed for i=1 and for i=6.<\/p>\n\n\n\n<p>The above results are achieved using the following code :&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(i == 1 || i == rows)\n\n\u00a0{\n\nfor (k = 1 ; k &lt;= (i * 2) - 1; k++ )\n\n{\n\nSystem.out.print(\"*\");\n\n}\n\n}<\/code><\/pre>\n\n\n\n<p>Finally, the further pattern with asterisk marks and hollow space can be achieved using the below code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (k = 1; k &lt;= (i * 2) - 1; k++ )\n\n{\n\nif(k == 1 || k == i * 2 - 1) {\n\nSystem.out.print(\"*\");\n\n}\n\nelse {\n\nSystem.out.print(\" \");\n\n}\n\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>&nbsp;<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><strong>k=1<\/strong><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td><strong>i=1<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>&nbsp;<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><strong>k=1<\/strong><\/td><td><strong>k=2<\/strong><\/td><td><strong>k=3<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=2<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td><\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>&nbsp;<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><strong>k=1<\/strong><\/td><td><strong>k=2<\/strong><\/td><td><strong>k=3<\/strong><\/td><td><strong>k=4<\/strong><\/td><td><strong>k=5<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=3<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>&nbsp;<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td><strong>k=1<\/strong><\/td><td><strong>k=2<\/strong><\/td><td><strong>k=3<\/strong><\/td><td><strong>k=4<\/strong><\/td><td><strong>k=5<\/strong><\/td><td><strong>k=6<\/strong><\/td><td><strong>k=7<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=4<\/strong><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>&nbsp;<\/strong><\/td><td>&nbsp;<\/td><td><strong>k=1<\/strong><\/td><td><strong>k=2<\/strong><\/td><td><strong>k=3<\/strong><\/td><td><strong>k=4<\/strong><\/td><td><strong>k=5<\/strong><\/td><td><strong>k=6<\/strong><\/td><td><strong>k=7<\/strong><\/td><td><strong>k=8<\/strong><\/td><td><strong>k=9<\/strong><\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=5<\/strong><\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><td><\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><td>*<\/td><td>&nbsp;<\/td><\/tr><tr><td><strong>i=6<\/strong><\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><td>*<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>In the above table it can be seen that for rows starting from i=2 to i=5, there is an asterisk (*) mark for k=1 and k &lt;= (i * 2) \u2013 1 so if the given condition is satisfied we will print asterisk marks and if the condition is not satisfied space is printed.&nbsp;&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Hollow Pyramid Pattern Using Numbers in Java<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">i. Code:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class HollowPyramidPattern {\n\n\u00a0\u00a0\u00a0\u00a0public static void main(String&#91;] args) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int rows = 6;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int number;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(\"Pyramid Pattern of Numbers by Itvedant\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int i, j, k;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (i = 1; i &lt;= rows; i++) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0number = 1;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (j = 1; j &lt;= rows - i; j++) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.print(\" \");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (i == 1 || i == rows) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (k = 1; k &lt;= (i * 2) - 1; k++) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.print(number);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0number++;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for (k = 1; k &lt;= (i * 2) - 1; k++) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (k == 1 || k == (i * 2) - 1) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.print(number);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0number++;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.print(\" \");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.out.println();\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0\u00a0\u00a0}\n\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">ii. Output:&nbsp;<\/h4>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXclj5O2pYQe2VKprtuQVFCeYFYSQWBpIPnaiXlfJnQ6N5ziUTvd3paMKwGqA3QQvTwWVlyPK4f-4Xto-w7wA8XeKE7LxfzRjG-QT-Fw1zg7SOwiboPZCLdg5xf3iNwHTqPXRnAvv_gBixI1J9hnc4rdQWaQ?key=fz8AD9TjJ0w-bpz1KzLbmg\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">iii. Explanation:<\/h4>\n\n\n\n<p>The hollow pyramid pattern with the number has the same pattern as the asterisk hollow pyramid. The only difference is in every row a number replaces the asterisk.<\/p>\n\n\n\n<p>So, a new variable \u201cnumber\u201d is considered which is initialized with value 1 for every new value of i(which represents row). Asterisk marks in the previous program are replaced with the \u201cnumber\u201d variable and the value of the \u201cnumber\u201d variable is incremented by 1 after the value is printed. If you\u2019re planning to become a Java developer, it\u2019s time to check out our <a href=\"https:\/\/www.itvedant.com\/java-full-stack-developer-course\">Java Course with a 100% Job Guarantee<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A hollow pyramid pattern is a triangular design in which only the outline is visible, and the interior part of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":163,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[11],"tags":[],"class_list":["post-159","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/posts\/159"}],"collection":[{"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":3,"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/posts\/159\/revisions\/162"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/media\/163"}],"wp:attachment":[{"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itvedant.com\/blog\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}