{"id":71105,"date":"2025-01-30T15:33:04","date_gmt":"2025-01-30T10:03:04","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=71105"},"modified":"2026-09-10T12:52:13","modified_gmt":"2026-09-10T07:22:13","slug":"star-patterns-in-java-for-your-next-interview","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/star-patterns-in-java-for-your-next-interview\/","title":{"rendered":"15 Star Patterns in Java for Interviews 2026: Complete Guide for Freshers"},"content":{"rendered":"\n<p>Ever walked into a Java interview and blanked on a pattern question you&#8217;d seen a dozen times before in practice? You&#8217;re not alone, and it usually comes down to memorizing code instead of understanding the logic underneath it.<\/p>\n\n\n\n<p><strong>Star patterns in Java are console-output exercises that use nested for loops to print asterisks in shapes like triangles, pyramids, and diamonds, testing whether you truly understand loop logic rather than just recognizing shapes.<\/strong> This guide covers all 15 patterns with working Java code, the logic behind each one, and the mistakes that actually cost candidates marks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR Summary<\/strong><\/h2>\n\n\n\n<ul>\n<li><strong>What it is:<\/strong> nested-loop exercises that print shapes using stars, testing loop logic over memorization<\/li>\n\n\n\n<li><strong>The 15 patterns:<\/strong> Right Triangle, Inverted Right Triangle, Left Triangle, Pyramid, Inverted Pyramid, Full Pyramid, Right Pascal&#8217;s Triangle, Hollow Pyramid, Diamond, Hollow Diamond, Sandglass, Hourglass, Butterfly, Hollow Butterfly, Hollow Square<\/li>\n\n\n\n<li><strong>Why companies ask them:<\/strong> they test nested loops, manual logic tracing, and clear explanation, all in one quick question<\/li>\n\n\n\n<li><strong>Time complexity:<\/strong> every pattern here runs in O(n\u00b2), since you&#8217;re touching roughly n rows and n columns<\/li>\n\n\n\n<li><strong>If short on time:<\/strong> prioritize Right Triangle, Pyramid, Diamond, Hollow Pyramid, and Butterfly first<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What are Star patterns in Java?<\/strong><\/h2>\n\n\n\n<p>Star patterns are beginner-friendly programming exercises that use nested loops, spaces, and conditional statements to print shapes like triangles, pyramids, diamonds, and squares to the console.<\/p>\n\n\n\n<p>Companies like TCS, Infosys, Wipro, Cognizant, and Accenture lean on these in screening rounds because they test three things at once: whether you actually understand nested loops, whether you can trace logic by hand before typing code, and whether you can explain your thinking clearly out loud.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.placementpreparation.io\/mock-test\/?utm_source=guvi&amp;utm_medium=blog_banner&amp;utm_campaign=star_patterns_in_java_for_your_next_interview_horizontal\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1200\" height=\"317\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/mock-test-horizontal-banner-placement-success-1200x317.png\" alt=\"mock test horizontal banner placement success\" class=\"wp-image-117109\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/mock-test-horizontal-banner-placement-success-1200x317.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/mock-test-horizontal-banner-placement-success-300x79.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/mock-test-horizontal-banner-placement-success-768x203.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/mock-test-horizontal-banner-placement-success-1536x406.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/mock-test-horizontal-banner-placement-success-2048x541.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/mock-test-horizontal-banner-placement-success-150x40.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">15 <strong>Star Patterns in Java: Interview Comparison Table<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Star Pattern<\/strong><\/td><td><strong>Difficulty<\/strong><\/td><td><strong>Main Logic<\/strong><\/td><td><strong>Loops Usually Required<\/strong><\/td><td><strong>Interview Priority<\/strong><\/td><\/tr><tr><td><strong>Right Triangle<\/strong><\/td><td>Easy<\/td><td>Increasing stars<\/td><td>2 nested loops<\/td><td>\u2b50\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Inverted Right Triangle<\/strong><\/td><td>Easy<\/td><td>Decreasing stars<\/td><td>2 nested loops<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Left Triangle<\/strong><\/td><td>Easy<\/td><td>Spaces + increasing stars<\/td><td>2 nested loops<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Pyramid<\/strong><\/td><td>Easy<\/td><td>Spaces + odd number of stars<\/td><td>2 nested loops<\/td><td>\u2b50\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Inverted Pyramid<\/strong><\/td><td>Easy<\/td><td>Increasing spaces + decreasing stars<\/td><td>2 nested loops<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Full Pyramid<\/strong><\/td><td>Medium<\/td><td>Upper + lower pyramid<\/td><td>Multiple loop blocks<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Pascal\u2019s Triangle Pattern<\/strong><\/td><td>Medium<\/td><td>Increasing + decreasing rows<\/td><td>Multiple loop blocks<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Hollow Pyramid<\/strong><\/td><td>Medium<\/td><td>Border conditions<\/td><td>Nested loops + if<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Diamond<\/strong><\/td><td>Medium<\/td><td>Pyramid + inverted pyramid<\/td><td>Multiple loop blocks<\/td><td>\u2b50\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Hollow Diamond<\/strong><\/td><td>Medium<\/td><td>Symmetrical border conditions<\/td><td>Nested loops + if<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Sandglass<\/strong><\/td><td>Medium<\/td><td>Inverted + upright pyramid<\/td><td>Multiple loop blocks<\/td><td>\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Hourglass<\/strong><\/td><td>Medium<\/td><td>Contraction + expansion<\/td><td>Multiple loop blocks<\/td><td>\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Butterfly<\/strong><\/td><td>Hard<\/td><td>Mirrored triangles + spaces<\/td><td>3 inner loops<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Hollow Butterfly<\/strong><\/td><td>Hard<\/td><td>Mirrored border conditions<\/td><td>Nested loops + if<\/td><td>\u2b50\u2b50\u2b50<\/td><\/tr><tr><td><strong>Hollow Square<\/strong><\/td><td>Medium<\/td><td>Border traversal<\/td><td>Nested loops + if<\/td><td>\u2b50\u2b50\u2b50\u2b50<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">15 Star Patterns In Java<\/figcaption><\/figure>\n\n\n\n<p><strong>Quick interview tip:<\/strong> If you have limited preparation time, prioritize the <strong>Right Triangle, Pyramid, Diamond, Hollow Pyramid, and Butterfly<\/strong> patterns because they cover the core ideas of increasing\/decreasing loops, spaces, symmetry, and conditional printing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Approach Any Star Patterns Problem<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/01-4-1200x630.png\" alt=\"How to Approach Any Star Patterns Problem\" class=\"wp-image-110828\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/01-4-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/01-4-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/01-4-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/01-4-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/01-4-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/01-4-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Every star pattern in <a href=\"https:\/\/www.guvi.in\/blog\/introduction-to-java\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java<\/a>, no matter how complex, breaks down the same way. You don&#8217;t need to memorise every pattern, you need to understand this mental framework:<\/p>\n\n\n\n<ol>\n<li><strong>Count the rows<\/strong> \u2014 the outer loop always runs n times (user input or fixed)<\/li>\n\n\n\n<li><strong>Identify what each row contains<\/strong> \u2014 spaces? stars? both?<\/li>\n\n\n\n<li><strong>Write one inner loop per element type<\/strong> \u2014 one for spaces, one for stars<\/li>\n\n\n\n<li><strong>Add <\/strong><a href=\"https:\/\/www.guvi.in\/hub\/java-programs-tutorial\/if-else-program\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>if conditions<\/strong><\/a><strong> only for hollow patterns<\/strong> \u2014 print * on borders, space inside<\/li>\n\n\n\n<li><strong>Test manually with n = 4<\/strong> \u2014 trace on paper before running<\/li>\n<\/ol>\n\n\n\n<p>Once you have this framework, any new pattern becomes a variation you can figure out on the spot.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>Star pattern questions are a great way to strengthen your understanding of loops, nested loops, and problem-solving logic. If you&#8217;re preparing for Java interviews, explore HCL GUVI&#8217;s <a href=\"https:\/\/www.guvi.in\/hub\/java-tutorial\/\" target=\"_blank\" rel=\"noreferrer noopener\">free Java Tutorial <\/a>to master core Java concepts, control statements, OOPs, collections, and more.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The 15 Star Patterns Programs<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/02-4-1200x630.png\" alt=\"The 15 Star Patterns Programs\" class=\"wp-image-110829\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/02-4-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/02-4-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/02-4-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/02-4-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/02-4-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/02-4-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Right Triangle Star Patterns<\/strong><\/h3>\n\n\n\n<p>A great starting point, the most fundamental nested loop pattern. The outer loop counts rows; the inner loop prints one star per column up to the row number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class RightTriangleStarPattern {\n\n&nbsp;&nbsp;&nbsp;&nbsp;public static void main(String&#91;] args) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner scanner = new Scanner(System.in);\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\"Enter number of rows: \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int rows = scanner.nextInt();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 1; i &lt;= rows; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ outer loop: row number\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) { &nbsp; &nbsp; &nbsp; &nbsp; \/\/ inner loop: stars = row number\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ move to next line\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}\n\n```\n\n**Output (n=5):**\n\n```\n\n*\n\n**\n\n***\n\n****\n\n*****<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Basic nested loop, incrementing inner loop<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Inverted Right Triangle Star Patterns<\/strong><\/h3>\n\n\n\n<p>Flip the logic; start from the full row and count down. Just change the outer loop to decrement from rows to 1.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = rows; i &gt;= 1; i--) { &nbsp; \/\/ outer loop counts down\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) {&nbsp; \/\/ stars = current row count\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=5):**\n\n```\n\n*****\n\n****\n\n***\n\n**\n\n*<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Decrementing outer loop<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Left Triangle Star Patterns<\/strong><\/h3>\n\n\n\n<p>Same star count as the right triangle, but now you print spaces before the stars to push them right-aligned.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = 1; i &lt;= rows; i++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) {&nbsp; \/\/ spaces for alignment\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) { &nbsp; &nbsp; &nbsp; &nbsp; \/\/ stars\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n&nbsp;&nbsp;&nbsp;*\n\n&nbsp;&nbsp;**\n\n&nbsp;***\n\n****<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Two inner loops, space management<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Pyramid Star Patterns<\/strong><\/h3>\n\n\n\n<p>The classic. You need spaces on the left for centering, and an odd number of stars per row (2i &#8211; 1). Interviewers love asking this one because the space logic trips up many candidates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = 1; i &lt;= rows; i++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) {&nbsp; &nbsp; \/\/ leading spaces\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) {&nbsp; \/\/ stars: 1, 3, 5, 7...\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n&nbsp;&nbsp;&nbsp;*\n\n&nbsp;&nbsp;***\n\n&nbsp;*****\n\n*******<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Space + star calculation, 2i &#8211; 1 formula<\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\"><strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong> <br \/><br \/>The formula 2i &#8211; 1 always gives odd numbers, that&#8217;s why a pyramid always has a clean point at the top. Row 1 = 1 star, row 2 = 3 stars, row 3 = 5 stars. Spot the pattern? It&#8217;s an arithmetic sequence with common difference 2.<\/div>\n\n\n\n<p class=\"has-text-align-center\"><strong>Notice how every pattern boils down to loops, conditions, and logical thinking? These are the same fundamentals used to solve coding interview questions. Strengthen your problem-solving skills with HCL GUVI&#8217;s <a href=\"https:\/\/www.guvi.in\/hub\/data-structures-and-algorithms-tutorial\/\" target=\"_blank\" rel=\"noreferrer noopener\">free Data Structures and Algorithms Tutorial<\/a>.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Inverted Pyramid Star Patterns<\/strong><\/h3>\n\n\n\n<p>Start with the widest row at the top, then shrink it. Space count increases as stars decrease.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = rows; i &gt;= 1; i--) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) {&nbsp; &nbsp; \/\/ increasing spaces\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) {&nbsp; \/\/ decreasing stars\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n*******\n\n&nbsp;*****\n\n&nbsp;&nbsp;***\n\n&nbsp;&nbsp;&nbsp;*<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Inverse relationship between spaces and stars<\/p>\n\n\n\n<p class=\"has-text-align-center\">Every role in UI\/UX from UX Research to Interaction Design is covered in <a href=\"https:\/\/guvi.in\/zen-class\/ui-ux-design-course\/?utm_source=blog&amp;utm_medium=hyperlink+&amp;utm_campaign=star-patterns-in-java-for-your-next-interview\" target=\"_blank\" rel=\"noreferrer noopener\">HCL GUVI\u2019s UI\/UX Design course<\/a>. You\u2019ll build skills across the full spectrum with real projects, mentor support, and placement assistance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Full Pyramid Star Patterns(Upward + Downward Combined)<\/strong><\/h3>\n\n\n\n<p>You join a pyramid and an inverted pyramid to form a rhombus shape. Two separate loop blocks, one going up, one going down.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Upper pyramid\n\nfor (int i = 1; i &lt;= rows; i++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n\/\/ Lower inverted pyramid (skip the middle row with rows-1)\n\nfor (int i = rows - 1; i &gt;= 1; i--) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n&nbsp;&nbsp;&nbsp;*\n\n&nbsp;&nbsp;***\n\n&nbsp;*****\n\n*******\n\n&nbsp;*****\n\n&nbsp;&nbsp;***\n\n&nbsp;&nbsp;&nbsp;*<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Two-part pattern, mirroring logic<\/p>\n\n\n\n<p>If you want to be more confident about Java and learn all its knacks, then consider enrolling in HCL GUVI&#8217;s<a href=\"https:\/\/www.guvi.in\/courses\/programming\/java-programming\/?utm_source=blog&amp;utm_medium=hyperlink+&amp;utm_campaign=star-patterns-in-java-for-your-next-interview\" target=\"_blank\" rel=\"noreferrer noopener\"> <\/a>Free Self-Paced<a href=\"https:\/\/www.guvi.in\/courses\/programming\/java-programming\/?utm_source=blog&amp;utm_medium=hyperlink+&amp;utm_campaign=star-patterns-in-java-for-your-next-interview\" target=\"_blank\" rel=\"noreferrer noopener\"> Java Programming Course<\/a> that covers everything from variables and control flow to OOP, at your own pace, in your language.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Right Pascal&#8217;s Triangle<\/strong> <strong>Star Patterns<\/strong><\/h3>\n\n\n\n<p>An upper right triangle joined with a downward-pointing one. Think of it as a &#8220;mountain&#8221; lying on its side.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = 1; i &lt;= rows; i++) { &nbsp; &nbsp; &nbsp; &nbsp; \/\/ upper: increasing\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\nfor (int i = rows - 1; i &gt;= 1; i--) {&nbsp; &nbsp; \/\/ lower: decreasing\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n*\n\n**\n\n***\n\n****\n\n***\n\n**\n\n*<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Combining ascending and descending triangles<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>8. Hollow Pyramid Star Patterns<\/strong><\/h3>\n\n\n\n<p>Same outer structure as the pyramid, but only border stars are printed. An if condition gates the interior; only the first column, last column, and bottom row get a *.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = 1; i &lt;= rows; i++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j == 1 || j == 2 * i - 1 || i == rows) { \/\/ border condition\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n&nbsp;&nbsp;&nbsp;*\n\n&nbsp;&nbsp;* *\n\n&nbsp;* &nbsp; *\n\n*******<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Conditional printing, border vs interior distinction<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>9. Diamond Star Patterns<\/strong><\/h3>\n\n\n\n<p>A diamond is a pyramid on top of an inverted pyramid, sharing no duplicate middle row. This is one of the most commonly asked medium-difficulty patterns.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Upper half\n\nfor (int i = 1; i &lt;= rows; i++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n\/\/ Lower half\n\nfor (int i = rows - 1; i &gt;= 1; i--) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n&nbsp;&nbsp;&nbsp;*\n\n&nbsp;&nbsp;***\n\n&nbsp;*****\n\n*******\n\n&nbsp;*****\n\n&nbsp;&nbsp;***\n\n&nbsp;&nbsp;&nbsp;*<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Pyramid + inverted pyramid combination<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>10. Hollow Diamond Star Patterns<\/strong><\/h3>\n\n\n\n<p>A hollow diamond prints only the outermost stars; spaces fill the inside. The condition checks if the star is on the first or last column of each row.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Upper hollow pyramid\n\nfor (int i = 1; i &lt;= rows; i++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j == 1 || j == 2 * i - 1) System.out.print(\"*\"); \/\/ only borders\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n\/\/ Lower hollow inverted pyramid\n\nfor (int i = rows - 1; i &gt;= 1; i--) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j == 1 || j == 2 * i - 1) System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n&nbsp;&nbsp;&nbsp;*\n\n&nbsp;&nbsp;* *\n\n&nbsp;* &nbsp; *\n\n* &nbsp; &nbsp; *\n\n&nbsp;* &nbsp; *\n\n&nbsp;&nbsp;* *\n\n&nbsp;&nbsp;&nbsp;*<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Border-only condition on a symmetric shape<\/p>\n\n\n\n<p class=\"has-text-align-center\">All six skills: user research, wireframing, visual design, interaction design, usability testing, and collaboration are taught in <a href=\"https:\/\/guvi.in\/zen-class\/ui-ux-design-course\/?utm_source=blog&amp;utm_medium=hyperlink+&amp;utm_campaign=star-patterns-in-java-for-your-next-interview\" target=\"_blank\" rel=\"noreferrer noopener\">HCL GUVI\u2019s UI\/UX Design course<\/a> through structured modules and real-world project assignments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>11. Sandglass Star Patterns<\/strong><\/h3>\n\n\n\n<p>Wide at the top and bottom, narrow in the middle like a sandglass. Start with the inverted pyramid, then build upward.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Top: inverted pyramid\nfor (int i = rows; i &gt;= 1; i--) {\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) System.out.print(\"*\");\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n}\n\/\/ Bottom: upright pyramid\nfor (int i = 2; i &lt;= rows; i++) {\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * i - 1; j++) System.out.print(\"*\");\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n}\n```\n**Output (n=4):**\n```\n*******\n&nbsp;*****\n&nbsp;&nbsp;***\n&nbsp;&nbsp;&nbsp;*\n&nbsp;&nbsp;***\n&nbsp;*****\n*******<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Inverted + upright pyramid join, loop starting point<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><a href=\"https:\/\/www.guvi.in\/blog\/pattern-programs-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pattern programs<\/a> are often used by interviewers to evaluate logical thinking before moving on to coding and DSA questions. Build a stronger foundation in algorithms, data structures, and problem-solving with HCL GUVI&#8217;s <a href=\"https:\/\/www.guvi.in\/hub\/data-structures-and-algorithms-tutorial\/\" target=\"_blank\" rel=\"noreferrer noopener\">free DSA Tutorial<\/a><\/strong> <strong>and become interview-ready faster.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>12. Hourglass Star Patterns<\/strong><\/h3>\n\n\n\n<p>Similar shape to the sandglass, but flipped: the widest rows sit at the outer edges, and the narrowest point sits in the middle. Count down from the full row count, then continue counting up from row 2.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = rows; i &gt;= 1; i--) {\n    for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n    for (int j = 1; j &lt;= 2 * i - 1; j++) System.out.print(\"*\");\n    System.out.println();\n}\nfor (int i = 2; i &lt;= rows; i++) {\n    for (int j = 1; j &lt;= rows - i; j++) System.out.print(\" \");\n    for (int j = 1; j &lt;= 2 * i - 1; j++) System.out.print(\"*\");\n    System.out.println();\n}<\/code><\/pre>\n\n\n\n<p><strong>Output (n=4):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*******\n *****\n  ***\n   *\n  ***\n *****\n*******<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> symmetric contraction followed by expansion.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>13. Butterfly Star Patterns<\/strong><\/h3>\n\n\n\n<p>This one asks you to print two mirrored right triangles on the same row, with a gap between them that shrinks as the rows increase.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Upper half\nfor (int i = 1; i &lt;= rows; i++) {\n    for (int j = 1; j &lt;= i; j++) System.out.print(\"*\");\n    for (int j = 1; j &lt;= 2 * (rows - i); j++) System.out.print(\" \");\n    for (int j = 1; j &lt;= i; j++) System.out.print(\"*\");\n    System.out.println();\n}\n\/\/ Lower half\nfor (int i = rows; i &gt;= 1; i--) {\n    for (int j = 1; j &lt;= i; j++) System.out.print(\"*\");\n    for (int j = 1; j &lt;= 2 * (rows - i); j++) System.out.print(\" \");\n    for (int j = 1; j &lt;= i; j++) System.out.print(\"*\");\n    System.out.println();\n}<\/code><\/pre>\n\n\n\n<p><strong>Output (n=4):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*      *\n**    **\n***  ***\n********\n********\n***  ***\n**    **\n*      *<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> three inner loops per row, mirror symmetry, and the gap formula.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>14. Hollow Butterfly Patterns<\/strong><\/h3>\n\n\n\n<p>Same structure as the butterfly, but only border positions print a star. Add a border condition inside each wing.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = 1; i &lt;= rows; i++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j == 1 || j == i) System.out.print(\"*\"); else System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * (rows - i); j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j == 1 || j == i) System.out.print(\"*\"); else System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\nfor (int i = rows; i &gt;= 1; i--) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j == 1 || j == i) System.out.print(\"*\"); else System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= 2 * (rows - i); j++) System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= i; j++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j == 1 || j == i) System.out.print(\"*\"); else System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=4):**\n\n```\n\n*&nbsp; &nbsp; &nbsp; *\n\n**&nbsp; &nbsp; **\n\n* *&nbsp; * *\n\n*&nbsp; **&nbsp; *\n\n*&nbsp; **&nbsp; *\n\n* *&nbsp; * *\n\n**&nbsp; &nbsp; **\n\n*&nbsp; &nbsp; &nbsp; *<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> Border conditions on mirrored wings<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>Complex patterns require more than memorization; they demand a clear understanding of loops, conditions, and program flow. Strengthen your Java fundamentals with HCL GUVI&#8217;s <a href=\"https:\/\/www.guvi.in\/hub\/java-tutorial\/\" target=\"_blank\" rel=\"noreferrer noopener\">free Java Tutorial<\/a> and gain the confidence to tackle interview questions independently.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>15. Hollow Square Patterns<\/strong><\/h3>\n\n\n\n<p>A 2D grid where only the border cells print a star. The condition is simple: first row, last row, first column, or last column.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (int i = 1; i &lt;= rows; i++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 1; j &lt;= rows; j++) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i == 1 || i == rows || j == 1 || j == rows) \/\/ border check\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\"*\");\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(\" \");\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();\n\n}\n\n```\n\n**Output (n=5):**\n\n```\n\n*****\n\n* &nbsp; *\n\n* &nbsp; *\n\n* &nbsp; *\n\n*****<\/code><\/pre>\n\n\n\n<p><strong>Concept tested:<\/strong> <a href=\"https:\/\/codesignal.com\/learn\/courses\/multidimensional-arrays-and-their-traversal-in-java\/lessons\/grid-traversal-finding-ascending-paths-in-2d-arrays-in-java\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">2D grid traversal<\/a>, multi-condition border check<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Beyond Stars: Number and Character Patterns<\/strong><\/h2>\n\n\n\n<p>Once an interviewer sees you&#8217;ve genuinely understood star patterns, a common follow-up is asking you to swap the stars for numbers or letters, using the exact same loop structure.<\/p>\n\n\n\n<ul>\n<li><strong>Number patterns:<\/strong> replace <code>System.out.print(\"*\")<\/code> with <code>System.out.print(j)<\/code> to print 1, 2, 3 instead of stars, or <code>System.out.print(i)<\/code> to repeat the row number across the row.<\/li>\n\n\n\n<li><strong>Character patterns:<\/strong> print letters using <code>(char)('A' + j - 1)<\/code> inside the loop to produce A, B, C sequences, a common variation on triangle and pyramid patterns specifically.<\/li>\n<\/ul>\n\n\n\n<p>The loop logic doesn&#8217;t change at all, only what gets printed inside it does. This is exactly why understanding the <em>why<\/em> behind each pattern matters more than memorizing 15 separate programs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Making Pattern Code More Efficient<\/strong><\/h2>\n\n\n\n<p>For small values of n, <code>System.out.print()<\/code> inside nested loops is perfectly fine.<\/p>\n\n\n\n<p>But if an interviewer asks how you&#8217;d optimize this for very large patterns, mention <code>StringBuilder<\/code>: build the full row as a string first, then print it once per row instead of calling <code>System.out.print()<\/code> on every single character.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>StringBuilder row = new StringBuilder();\nfor (int j = 1; j &lt;= i; j++) {\n    row.append(\"*\");\n}\nSystem.out.println(row);<\/code><\/pre>\n\n\n\n<p>This reduces the number of I\/O calls from n\u00b2 down to n, which is a genuinely good answer if the question comes up.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Top Star Patterns in Java for Interviews in India 2026<\/strong><\/h2>\n\n\n\n<p>For Java interviews in India, star-pattern questions are useful practice for understanding nested loops, conditional logic, row-column relationships, and output formatting.&nbsp;<\/p>\n\n\n\n<p>Current Java pattern guides continue to position these problems as interview and logic-building exercises.<\/p>\n\n\n\n<p>If you&#8217;re preparing for fresher or entry-level coding rounds in 2026, focus first on these patterns:<\/p>\n\n\n\n<ul>\n<li><strong>Right Triangle<\/strong>: builds basic nested-loop understanding.<\/li>\n\n\n\n<li><strong>Pyramid<\/strong>: introduces spaces and the 2 * i &#8211; 1 star formula.<\/li>\n\n\n\n<li><strong>Inverted Pyramid<\/strong>: tests reverse loop logic.<\/li>\n\n\n\n<li><strong>Diamond<\/strong>: combines an upward and downward pattern.<\/li>\n\n\n\n<li><strong>Hollow Pyramid<\/strong>: introduces conditional border printing.<\/li>\n\n\n\n<li><strong>Butterfly<\/strong>: tests symmetry, spacing, and multiple inner loops.<\/li>\n\n\n\n<li><strong>Hollow Square<\/strong>: strengthens row-column and boundary conditions.<\/li>\n<\/ul>\n\n\n\n<p>The goal isn&#8217;t to memorize 15 separate programs. Instead, understand how <strong>rows, columns, spaces, stars, and conditions<\/strong> interact.&nbsp;<\/p>\n\n\n\n<p>Once you can identify those relationships, you can usually build a new pattern during an interview rather than recalling it line by line.<\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\">\n  <strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1Did You Know?<\/strong> \n  <br \/><br \/> \nJava was originally called Oak during development. The name was later changed to Java before its public release in 1995\u2014so the language behind these simple star patterns has a history that goes far beyond interview questions.\n\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Mistakes to Avoid in Interviews<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/03-4-1200x630.png\" alt=\"Common Mistakes to Avoid in Interviews\" class=\"wp-image-110831\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/03-4-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/03-4-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/03-4-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/03-4-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/03-4-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/05\/03-4-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p>Even if you know the code, these slip-ups can cost you:<\/p>\n\n\n\n<ul>\n<li><strong>Off-by-one errors<\/strong>: check whether your loop starts at 0 or 1 and whether it ends at &lt; n or &lt;= n<\/li>\n\n\n\n<li><strong>Forgetting <\/strong><strong>System.out.println()<\/strong>: missing the newline after each row collapses your pattern into one line<\/li>\n\n\n\n<li><strong>Wrong space formula<\/strong>: for pyramids, spaces = rows &#8211; i, not i &#8211; 1 (they give different results for off-center alignment)<\/li>\n\n\n\n<li><strong>Explaining nothing<\/strong>: writing silent code in an interview is a red flag; narrate your loop logic as you write it<\/li>\n\n\n\n<li><strong>Hardcoding <\/strong><strong>n<\/strong>: always take n as user input via Scanner unless told otherwise<\/li>\n<\/ul>\n\n\n\n<p class=\"has-text-align-center\">Colour theory, typography, and layout composition are the visual design fundamentals that define great UI work. HCL GUVI&#8217;s <a href=\"https:\/\/guvi.in\/zen-class\/ui-ux-design-course\/?utm_source=blog&amp;utm_medium=hyperlink+&amp;utm_campaign=star-patterns-in-java-for-your-next-interview\" target=\"_blank\" rel=\"noreferrer noopener\">UI\/UX Design course<\/a> includes dedicated visual design modules with real client-grade project feedback.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>While pattern programs improve logical thinking, interview success also depends on strong coding fundamentals and problem-solving skills. <\/strong><\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>Combine <a href=\"https:\/\/www.guvi.in\/hub\/java-programs-tutorial\/\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/hub\/java-programs-tutorial\/\" target=\"_blank\" rel=\"noreferrer noopener\">Java practice with Data Structures and Algorithms<\/a> to prepare effectively for technical interviews.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Wrapping Up<\/strong><\/h2>\n\n\n\n<p>Star patterns programs aren&#8217;t just interview filler, they&#8217;re a genuine test of how you think through a problem step by step.&nbsp;<\/p>\n\n\n\n<p>If you can look at a diamond or a butterfly and immediately start breaking it into rows, loops, and conditions, you&#8217;ve built the kind of logical thinking that carries over into algorithms, data structures, and real-world Java development.<\/p>\n\n\n\n<p>The 15 star patterns in this guide cover everything from basic triangles to complex hollow butterflies.&nbsp;<\/p>\n\n\n\n<p>Work through them in order, test each one with n = 4 and n = 5, and try explaining your logic out loud; that last part is what interviewers actually remember.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1774876583103\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>1. What is a star pattern program in Java?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A star pattern program in Java is a program that uses nested for loops to print asterisks (*) in geometric shapes on the console, such as triangles, pyramids, diamonds, and squares. They test loop logic and are standard in Java screening interviews.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1774876585868\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>2. Why are pattern programs asked in Java interviews?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Interviewers use them to test nested loop understanding, manual logic tracing, and the ability to explain code clearly, all in one compact question. They&#8217;re time-efficient tests of fundamental programming skill.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1774876589248\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>3. What is the most commonly asked star pattern in interviews?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The pyramid pattern (2i &#8211; 1 stars per row) is the most frequently asked, followed closely by the diamond and the right triangle. If you&#8217;re short on time, master these three first.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1774876594552\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>4. What is the difference between a solid and hollow star pattern?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>In a solid pattern, every cell within the shape boundary prints a *. In a hollow pattern, only the border cells print *, and interior cells print a space. A single if condition is all that separates them.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1774876600990\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>5. Can I use while loops instead of for loops for star patterns?<\/strong>\u00a0<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, any for loop can be rewritten as a while loop. However, for loops are preferred in interviews because they&#8217;re more compact and clearly express the start, condition, and increment in one line.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788181444177\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>6. What is the easiest star pattern in Java?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The right triangle is one of the easiest star patterns in Java for beginners. It uses two nested for loops: the outer loop controls the rows, while the inner loop prints stars based on the current row number.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788181460429\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>7. How do you print a star pattern in Java?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can print a star pattern in Java using nested loops. Typically, the outer loop controls the number of rows, while one or more inner loops control stars and spaces. For hollow patterns, an if condition determines whether to print a star or a space.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788181474710\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>8. Which star pattern is commonly asked in Java interviews?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Common interview practice patterns include the right triangle, pyramid, inverted pyramid, diamond, hollow pyramid, and butterfly patterns. These patterns test nested loops, spacing, symmetry, and conditional logic.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788181492845\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>9. How do I solve star pattern problems in Java?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Start by identifying the number of rows, then determine what each row contains: stars, spaces, or both. Next, assign an outer loop for rows and inner loops for each element type. For hollow patterns, add conditions for the boundary.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788181509108\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>10. Are star patterns important for Java interviews?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes. Star patterns are useful for testing basic programming logic, particularly nested loops, conditions, row-column relationships, and the ability to translate a visual pattern into code. They are especially useful for beginners preparing for coding and technical screening rounds. Current Java pattern-programming guides continue to include them as interview preparation topics.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Ever walked into a Java interview and blanked on a pattern question you&#8217;d seen a dozen times before in practice? You&#8217;re not alone, and it usually comes down to memorizing code instead of understanding the logic underneath it. Star patterns in Java are console-output exercises that use nested for loops to print asterisks in shapes [&hellip;]<\/p>\n","protected":false},"author":65,"featured_media":110827,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[720,719],"tags":[],"views":"26856","authorinfo":{"name":"Jebasta","url":"https:\/\/www.guvi.in\/blog\/author\/jebasta\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2025\/01\/Feature-image-300x116.png","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/71105"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=71105"}],"version-history":[{"count":26,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/71105\/revisions"}],"predecessor-version":[{"id":138350,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/71105\/revisions\/138350"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/110827"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=71105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=71105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=71105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}