The hollow plus star pattern draws the outline of a thick plus sign, the kind used for a first-aid symbol. Each arm is n stars wide and the whole shape fits in a square.
Quick answer: Think of the grid as three bands of rows: the top arm, the middle bar and the bottom arm. In the arms, print the two side edges and the end row. On the two rows where the arms meet the bar, print everything except the gap between the arms. In the bar’s middle rows, print only the far left and right columns.
This program is part of the Star Patterns collection.
Table of contents8 sections
Hollow Plus Star Pattern output
Output (n = 3):
*** * * *** *** * * *** *** * * ***

How the hollow plus star pattern works
A thick plus is the middle n columns plus the middle n rows of a (3n − 2)-wide square. Its outline needs a different rule in each band. The arm bands have short vertical edges and a closed end. The two rows where the bar starts and ends draw the shoulders on both sides. The rows inside the bar only show the outer ends. Writing one condition per band, joined with ||, keeps the logic readable.
- Run the outer loop for
ifrom1to3 × n − 2, one row per pass. - Go through
3 × n − 2positions in the row. Print stars where((i < n or i > 2 × n − 1) and (j = n or j = 2 × n − 1 or ((i = 1 or i = 3 × n − 2) and j ≥ n and j ≤ 2 × n − 1))) or ((i = n or i = 2 × n − 1) and (j ≤ n or j ≥ 2 × n − 1)) or (i > n and i < 2 × n − 1 and (j = 1 or j = 3 × n − 2)); print spaces everywhere else. - Move to the next line.
Key takeaways
- The plus is the middle columns plus the middle rows of a square grid.
- Each band of rows has its own simple outline rule.
- The shoulder rows are where the arms meet the bar.
- With
n = 3each arm is 3 stars wide and 2 rows long.
Hollow Plus Star Pattern in C
#include <stdio.h>
int main(void) {
int n = 3;
for (int i = 1; i <= 3 * n - 2; i++) {
for (int j = 1; j <= 3 * n - 2; j++) {
if (((i < n || i > 2 * n - 1) && (j == n || j == 2 * n - 1 || ((i == 1 || i == 3 * n - 2) && j >= n && j <= 2 * n - 1))) || ((i == n || i == 2 * n - 1) && (j <= n || j >= 2 * n - 1)) || (i > n && i < 2 * n - 1 && (j == 1 || j == 3 * n - 2)))
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}Hollow Plus Star Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 3;
for (int i = 1; i <= 3 * n - 2; i++) {
for (int j = 1; j <= 3 * n - 2; j++) {
if (((i < n || i > 2 * n - 1) && (j == n || j == 2 * n - 1 || ((i == 1 || i == 3 * n - 2) && j >= n && j <= 2 * n - 1))) || ((i == n || i == 2 * n - 1) && (j <= n || j >= 2 * n - 1)) || (i > n && i < 2 * n - 1 && (j == 1 || j == 3 * n - 2)))
cout << "*";
else
cout << " ";
}
cout << endl;
}
return 0;
}Hollow Plus Star Pattern in Java
public class HollowPlusStar {
public static void main(String[] args) {
int n = 3;
for (int i = 1; i <= 3 * n - 2; i++) {
for (int j = 1; j <= 3 * n - 2; j++) {
if (((i < n || i > 2 * n - 1) && (j == n || j == 2 * n - 1 || ((i == 1 || i == 3 * n - 2) && j >= n && j <= 2 * n - 1))) || ((i == n || i == 2 * n - 1) && (j <= n || j >= 2 * n - 1)) || (i > n && i < 2 * n - 1 && (j == 1 || j == 3 * n - 2)))
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}Hollow Plus Star Pattern in Python
n = 3
for i in range(1, 3 * n - 2 + 1):
for j in range(1, 3 * n - 2 + 1):
if ((i < n or i > 2 * n - 1) and (j == n or j == 2 * n - 1 or ((i == 1 or i == 3 * n - 2) and j >= n and j <= 2 * n - 1))) or ((i == n or i == 2 * n - 1) and (j <= n or j >= 2 * n - 1)) or (i > n and i < 2 * n - 1 and (j == 1 or j == 3 * n - 2)):
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 is this different from the plus sign pattern?
The plus sign pattern draws one line across and one line down. This one draws the outline of a thick plus with a hollow inside.
How do I make a solid thick plus?
Print a star whenever j is between n and 2n − 1 or i is between n and 2n − 1. That fills both bands completely.
Why does the condition look long?
Because it lists the outline band by band. Breaking it into three named booleans, such as inArm, onShoulder and inBar, makes it easier to read in your own code.










