The hollow parallelogram star pattern draws only the border of a slanted rectangle: a full top and bottom row of stars and two parallel slanted sides. It is the outline of the parallelogram star pattern.
Quick answer: Row i starts with n − i spaces and then covers 2n columns, from n − i + 1 to 3n − i. Print a star on the first and last row and at the first and last column of each row’s block; everything else is a space.
This program is part of the Star Patterns collection.
Table of contents8 sections
Hollow Parallelogram Star Pattern output
Output (4 rows, 8 columns):
******** * * * * ********

How the hollow parallelogram star pattern works
The solid parallelogram is a block of 2n stars that shifts one place left each row. To hollow it out, keep the same block but test where you are in it. Top and bottom rows are printed in full; on the rows in between only the two ends of the block are stars. The first part of the test, j > n − i, keeps the indent out of the picture.
- Run the outer loop for
ifrom1ton, one row per pass. - Go through
3 × n − ipositions in the row. Print stars wherej > n − i and (i = 1 or i = n or j = n − i + 1 or j = 3 × n − i); print spaces everywhere else. - Move to the next line.
Key takeaways
- Each row covers columns
n − i + 1to3n − i: 2n wide, shifted left each row. - Full top and bottom rows close the shape.
- The two slanted sides are the first and last column of the block.
- The condition
j > n − iskips the leading spaces.
Hollow Parallelogram Star Pattern in C
#include <stdio.h>
int main(void) {
int n = 4;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 3 * n - i; j++) {
if (j > n - i && (i == 1 || i == n || j == n - i + 1 || j == 3 * n - i))
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}Hollow Parallelogram Star Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 4;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 3 * n - i; j++) {
if (j > n - i && (i == 1 || i == n || j == n - i + 1 || j == 3 * n - i))
cout << "*";
else
cout << " ";
}
cout << endl;
}
return 0;
}Hollow Parallelogram Star Pattern in Java
public class HollowParallelogramStar {
public static void main(String[] args) {
int n = 4;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 3 * n - i; j++) {
if (j > n - i && (i == 1 || i == n || j == n - i + 1 || j == 3 * n - i))
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}Hollow Parallelogram Star Pattern in Python
n = 4
for i in range(1, n + 1):
for j in range(1, 3 * n - i + 1):
if j > n - i and (i == 1 or i == n or j == n - i + 1 or j == 3 * n - i):
print("*", end="")
else:
print(" ", end="")
print()Time and space complexity
The program prints one character for each position in the pattern, so for n rows it runs in O(n²) time. It only needs a few loop variables, so the extra memory is O(1).
Frequently asked questions
How do I make it lean the other way?
Indent each row by i − 1 spaces instead, as in the mirrored hollow parallelogram. The block then moves right as you go down.
How do I change the width?
Replace 2n with any width w: the block runs from n − i + 1 to n − i + w, and the right edge test becomes j == n − i + w.
Why is the bottom row not indented?
On the last row n − i = 0, so the block starts at the left margin. Each row above it starts one column further right.











