This page lists the most popular and available Java Star Pattern Programs with multiple examples using loops and functions.
Please refer to the Learn Java and Java Programming Examples to get the basics and the complete list of programs. For the remaining patterns, such as Alphabet and Number, refer to the below URLs.
TIP: Before practicing these Java Star Pattern Programs, I suggest you refer to the Java while loop, Java for loop, and Java do while loop to understand how the values change at each iteration.
Java Star Pattern Programs
The following are the frequently asked star pattern programs in Java programming interviews. We have given the best approach to create each pattern and provided the hyperlink to delve deep into them.
Print Alphabet A Pattern of Stars
For information on printing Java Alphabet A Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter the Number = ");
int rw = sc.nextInt();
for (int i = 0 ; i < rw; i++ )
{
for (int j = 0 ; j <= rw/2; j++ )
{
if((i == 0 && j != 0 && j != rw/2) || i == rw / 2 ||
(j == 0 || j == rw /2 ) && i != 0)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println("\n");
}
}
}
Output
Enter the Number = 10
****
* *
* *
* *
* *
******
* *
* *
* *
* *
Print Christmas Tree
For more information on Java Christmas Tree Star Pattern
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Chirstmas Tree Width & Height = ");
int w = sc.nextInt();
int h = sc.nextInt();
int sp = w * h;
int x, i, j, k, n = 1;
for (x = 1; x <= h; x++) {
for (i = n; i <= w; i++) {
for (j = sp; j >= i; j--) {
System.out.print(" ");
}
for (k = 1; k <= i; k++) {
System.out.print("* ");
}
System.out.println();
}
n = n + 2;
w = w + 2;
}
for (i = 1; i <= h - 1; i++) {
for (j = sp - 3; j >= 0; j--) {
System.out.print(" ");
}
for (k = 1; k <= h - 1; k++) {
System.out.print("* ");
}
System.out.println();
}
}
}
Output
Enter Chirstmas Tree Width & Height = 5 3
*
* *
* * *
* * * *
* * * * *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* *
* *
Exponentially Increased Star Pattern
For more information on Java Exponentially Increased Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Exponentially Increased Pattern Rows = ");
int rw = sc.nextInt();
for (int i = 0; i < rw; i++ )
{
for (int j = 1 ; j <= Math.pow(2, i); j++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Exponentially Increased Pattern Rows = 5
*
**
****
********
****************
Java Program to Print Diamond Pattern of Stars
For more information on Java Diamond Star patterns.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, rw;
System.out.print("Enter Diamond Rows = ");
rw = sc.nextInt();
for (i = 1 ; i <= rw; i++ )
{
printItems(rw, i);
}
for (i = rw - 1 ; i > 0; i-- )
{
printItems(rw, i);
}
}
public static void printItems(int rw, int i)
{
for (int j = 1 ; j <= rw - i; j++ )
{
System.out.print(" ");
}
for (int k = 1 ; k <= i * 2 - 1; k++ )
{
System.out.print("*");
}
System.out.println();
}
}
Output
Enter Diamond Rows = 9
*
***
*****
*******
*********
***********
*************
***************
*****************
***************
*************
***********
*********
*******
*****
***
*
Half Diamond Star Pattern
For more information on the Java Program to Print Half Diamond Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i;
System.out.print("Enter Rows = ");
int rw = sc.nextInt();
for (i = 1; i <= rw; i++) {
result(rw, i);
}
for (i = rw - 1; i > 0; i--) {
result(rw, i);
}
}
public static void result(int rw, int i) {
for (int j = 1; j <= i; j++)
{
System.out.print("*");
}
System.out.println();
}
}
Output
Enter Rows = 9
*
**
***
****
*****
******
*******
********
*********
********
*******
******
*****
****
***
**
*
Hollow Diamond Star Pattern program
For more information on the Java Hollow Diamond Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, rw;
System.out.print("Enter Hollow Diamond Star Pattern rows = ");
rw = sc.nextInt();
for (i = 1; i <= rw; i++) {
result(rw, i);
}
for (i = rw - 1; i > 0; i--) {
result(rw, i);
}
}
public static void result(int rw, int i) {
for (int j = 1; j <= rw - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i * 2 - 1; k++) {
if (k == 1 || k == i * 2 - 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
Output
Enter Hollow Diamond Star Pattern rows = 8
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
Hollow Diamond Pattern inside a Square
For more information on the Java program to print Hollow Diamond inside a Square star.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, j, k;
System.out.print("Enter Rows = ");
int rw = sc.nextInt();
for (i = 1; i <= rw; i++) {
for (j = i; j <= rw; j++) {
System.out.print("*");
}
for (j = 1; j <= 2 * i - 2; j++) {
System.out.print(" ");
}
for (k = i; k <= rw; k++) {
System.out.print("*");
}
System.out.println();
}
for (i = 1; i <= rw; i++) {
for (j = 1; j <= i; j++) {
System.out.print("*");
}
for (k = 2 * i - 2; k < 2 * rw - 2; k++) {
System.out.print(" ");
}
for (k = 1; k <= i; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Hollow Diamond Pattern inside a Square Rows = 8
****************
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
****************
Mirrored Half Diamond Star Pattern
For more information on the Java Mirrored Half Diamond Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i;
System.out.print("Enter Mirrored Half Diamond Star Pattern Rows = ");
int rw = sc.nextInt();
for (i = 1; i <= rw; i++) {
result(rw, i);
}
for (i = rw - 1; i > 0; i--) {
result(rw, i);
}
}
public static void result(int rw, int i) {
for (int j = 1; j <= rw - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
System.out.print("*");
}
System.out.println();
}
}
Output
Enter Mirrored Half Diamond Star Pattern Rows = 8
*
**
***
****
*****
******
*******
********
*******
******
*****
****
***
**
*
Java Pyramid Star Pattern Programs
For more information on the Java Pyramid Star Pattern. If you want the complete list of Java Pyramid pattern programs.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Rows = ");
int rw = sc.nextInt();
for (int i = 1; i <= rw; i++) {
for (int j = 0; j < rw - i; j++) {
System.out.print(" ");
}
for (int k = 0; k < (i * 2) - 1; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Rows = 10
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
Hollow Pyramid Star Pattern
For more information on the Java Hollow Pyramid Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Hollow Pyramid Star Pattern Rows = ");
int rows = sc.nextInt();
int i, j, k;
for (i = 1; i <= rows; i++) {
for (j = 1; j <= rows - i; j++)
{
System.out.print(" ");
}
if (i == 1 || i == rows)
{
for (k = 1; k <= (i * 2) - 1; k++)
{
System.out.print("*");
}
}
else {
for (k = 1; k <= (i * 2) - 1; k++)
{
if (k == 1 || k == i * 2 - 1)
{
System.out.print("*");
} else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
Output
Enter Hollow Pyramid Star Pattern Rows = 13
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*************************
Inverted Pyramid Pattern of Stars
For more information on the Java Inverted Pyramid Pattern of Stars.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Inverted Pyramid Pattern Rows = ");
int rows = sc.nextInt();
for (int i = rows; i >= 1; i--)
{
for (int j = 0; j < rows - i; j++)
{
System.out.print(" ");
}
for (int k = 0; k != (2 * i) - 1; k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Inverted Pyramid Pattern Rows = 12
***********************
*********************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
Hollow Inverted Pyramid of Stars
For more information on the Java Hollow Inverted Pyramid Pattern of Stars.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Hollow Inverted Pyramid Rows = ");
int rows = sc.nextInt();
for (int i = rows ; i > 0; i-- )
{
for (int j = 1 ; j <= rows - i; j++ )
{
System.out.print(" ");
}
for (int k = 1 ; k <= (2 * i) - 1; k++ )
{
if (i == 1 || i == rows || k == 1 || k == (2 * i) - 1)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
Output
Enter Hollow Inverted Pyramid Rows = 9
*****************
* *
* *
* *
* *
* *
* *
* *
*
Java Right Angled Triangle Star Pattern Programs
For more information on the Java Program to Print Right Angled Triangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Right Angled Triangle Pattern Rows = ");
int rows = sc.nextInt();
for (int i = 1 ; i <= rows; i++ )
{
for (int j = 1 ; j <= i; j++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Right Angled Triangle Pattern Rows = 12
*
**
***
****
*****
******
*******
********
*********
**********
***********
************
Hollow Right Angled Triangle Pattern of Stars
For more information on Printing Java Hollow Right Angled Triangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Hollow Right Angled Triangle Pattern Rows = ");
int rows = sc.nextInt();
for (int i = 1 ; i <= rows; i++ )
{
for (int j = 1 ; j <= i; j++ )
{
if(i == 1 || i == rows || j == 1 || j == i)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
Output
Enter Hollow Right Angled Triangle Pattern Rows = 14
*
**
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
**************
Print Inverted Right Triangle Star Pattern
For more information on the Java Inverted Right Triangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Inverted Right Triangle Pattern Rows = ");
int rows = sc.nextInt();
for (int i = rows; i > 0; i-- )
{
for (int j = 0 ; j < i; j++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Inverted Right Triangle Pattern Rows = 15
***************
**************
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
Hollow Inverted Right Triangle Star Pattern
For more information on the Java Hollow Inverted Right Triangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Hollow Inverted Right Triangle Pattern Rows = ");
int rows = sc.nextInt();
for (int i = rows; i > 0; i--)
{
if (i == 1 || i == rows)
{
for (int j = 1; j <= i; j++)
{
System.out.print("*");
}
}
else {
for (int k = 1; k <= i; k++)
{
if (k == 1 || k == i) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
Output
Enter Hollow Inverted Right Triangle Pattern Rows = 13
*************
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
**
*
Inverted Mirrored Right Triangle Star Pattern
For more information on the Java Inverted Mirrored Right Triangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Inverted Mirrored Right Triangle Pattern Rows = ");
int rows = sc.nextInt();
for (int i = rows; i > 0; i-- )
{
for (int j = rows - i ; j > 0; j-- )
{
System.out.print(" ");
}
for (int k = 0 ; k < i; k++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Inverted Mirrored Right Triangle Pattern Rows = 12
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
Mirrored Right Triangle Star Pattern
For more information on the Java Mirrored Right Triangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Mirrored Right Triangle Pattern Rows = ");
int rows = sc.nextInt();
for (int i = 1 ; i <= rows; i++ )
{
for (int j = 0 ; j < rows - i; j++ )
{
System.out.print(" ");
}
for (int k = 0 ; k < i; k++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Mirrored Right Triangle Pattern Rows = 9
*
**
***
****
*****
******
*******
********
*********
Reverse Mirrored Right Triangle Star Pattern
For more information on Printing Java Reverse Mirrored Right Triangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Reverse Mirrored Right Triangle Rows = ");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows; j++)
{
if (j < i) {
System.out.print(" ");
} else {
System.out.print("*");
}
}
System.out.println();
}
}
}
Output
Enter Reverse Mirrored Right Triangle Rows = 14
**************
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
Java Triangle Star Pattern Programs
For more information on Printing the Java Triangle Star Pattern >> Click Here.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Triangle Rows = ");
int rows = sc.nextInt();
for (int i = 1 ; i <= rows; i++ )
{
for (int j = 1 ; j <= i; j++ )
{
System.out.print("* ");
}
System.out.println("");
}
}
}
Output
Enter Triangle Rows = 10
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
Downward Triangle
For more information on Java Downward Triangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Downward Triangle Rows = ");
int rw = sc.nextInt();
for (int i = rw -1 ; i >= 0; i-- )
{
for (int j = 0 ; j <= i; j++ )
{
System.out.print("* ");
}
System.out.println();
}
}
}
Output
Enter Downward Triangle Rows = 13
* * * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Print Left Pascal Triangle of Stars
For more information on the Java Left Pascal Triangle of Stars pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i;
System.out.print("Enter Left Pascals Triangle Pattern Rows = ");
int rows = sc.nextInt();
for (i = 1; i <= rows; i++) {
result(rows, i);
}
for (i = rows - 1; i >= 1; i--) {
result(rows, i);
}
}
public static void result(int rows, int i) {
for (int j = i; j < rows; j++)
{
System.out.print(" ");
}
for (int k = 1; k <= i; k++)
{
System.out.print("* ");
}
System.out.println();
}
}
Output
Enter Left Pascals Triangle Pattern Rows = 8
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Hollow Left Pascal Triangle of Stars
For more information on the Java Hollow Left Pascal Triangle of Stars pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, j, k;
System.out.print("Enter Hollow Left Pascals Triangle Rows = ");
int rows = sc.nextInt();
for (i = 1; i <= rows; i++) {
for (j = rows; j > i; j--) {
System.out.print(" ");
}
for (k = 1; k <= i; k++) {
if (k == 1 || k == i) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (i = 1; i <= rows - 1; i++) {
for (j = 1; j <= i; j++) {
System.out.print(" ");
}
for (k = rows - 1; k >= i; k--) {
if (k == rows - 1 || k == i) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
Output
Enter Hollow Left Pascals Triangle Rows = 10
*
**
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
**
*
Right Pascal Triangle of Stars
For more information on the Java Right Pascal Triangle of Stars pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i;
System.out.print("Enter Right Pascals Triangle Pattern Rows = ");
int rows = sc.nextInt();
for (i = 0; i < rows; i++) {
result(rows, i);
}
for (i = rows; i >= 0; i--) {
result(rows, i);
}
}
public static void result(int rows, int i) {
for (int j = 0; j < i; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
Output
Enter Right Pascals Triangle Pattern Rows = 9
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Hollow Right Pascal Triangle of Stars
For more information on the Java Hollow Right Pascal Triangle of Stars pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, j, k, rows;
System.out.print("Enter Hollow Right Pascals Triangle Rows = ");
rows = sc.nextInt();
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
if (j == 1 || j == i) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (i = 1; i <= rows - 1; i++) {
for (j = rows - 1; j >= i; j--) {
if (j == rows - 1 || j == i || i == rows) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
for (k = 1; k < i; k++) {
System.out.print(" ");
}
System.out.println();
}
}
}
Output
Enter Hollow Right Pascals Triangle Rows = 8
*
**
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
**
*
Java Square Star Pattern Programs
For more information on printing the Java Square of Stars pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Please Enter any Side of a Square : ");
int side = sc.nextInt();
for(int i = 1; i <= side; i++)
{
for(int j = 1; j <= side; j++)
{
System.out.print("*");
}
System.out.print("\n");
}
}
}
Output
Please Enter any Side of a Square : 12
************
************
************
************
************
************
************
************
************
************
************
************
Hollow Square Pattern of Stars
For more information on the Java Hollow Square of Stars pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Please Enter any Side of a Square : ");
int side = sc.nextInt();
for(int i = 0; i < side; i++)
{
for(int j = 0; j < side; j++)
{
if (i == 0 || i == side - 1 || j == 0 || j == side - 1)
{
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.print("\n");
}
}
}
Output
Please Enter any Side of a Square : 14
* * * * * * * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * * * * * * *
Hollow Square with Diagonals
For more information on the Java Hollow Square with Diagonals Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Hollow Square with Diagonals side = ");
int s = sc.nextInt();
for (int i = 1; i <= s; i++)
{
for (int j = 1; j <= s; j++)
{
if (i == 1 || i == s || i == j || j == 1 || j == s || j == s - i + 1) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
Output
Enter Hollow Square with Diagonals side = 10
* * * * * * * * * *
* * * *
* * * *
* * * *
* * * *
* * * *
* * * *
* * * *
* * * *
* * * * * * * * * *
Java Rhombus Star Pattern Programs
For more information on the Java Program to Print Rhombus Pattern of Stars.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Please Enter Rhombus Pattern Rows = ");
int rows = sc.nextInt();
for (int i = 1 ; i <= rows; i++ )
{
for (int j = 1 ; j <= rows - i; j++ )
{
System.out.print(" ");
}
for (int k = 1 ; k <= rows; k++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
Output
Please Enter Rhombus Pattern Rows = 9
*********
*********
*********
*********
*********
*********
*********
*********
*********
Hollow Rhombus Pattern of Stars
For more information on the Java Hollow Rhombus Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Hollow Rhombus Pattern Rows = ");
int rows = sc.nextInt();
for (int i = 1 ; i <= rows; i++ )
{
for (int j = 1 ; j <= rows - i; j++ )
{
System.out.print(" ");
}
for (int k = 1 ; k <= rows; k++ )
{
if (i == 1 || i == rows || k == 1 || k == rows) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
Output
Enter Hollow Rhombus Pattern Rows = 12
* * * * * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * * * * *
Mirrored Rhombus Pattern of Stars
For more information on Printing Java Mirrored Rhombus Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Mirrored Rhombus Pattern Rows = ");
int rows = sc.nextInt();
for (int i = 1 ; i <= rows; i++ )
{
for (int j = 1 ; j < i; j++ )
{
System.out.print(" ");
}
for (int k = 1 ; k <= rows; k++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Mirrored Rhombus Pattern Rows = 13
*************
*************
*************
*************
*************
*************
*************
*************
*************
*************
*************
*************
*************
Hollow Mirrored Rhombus Star Pattern
For more information on the Java Program to Print the Hollow Mirrored Rhombus Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Hollow Mirrored Rhombus Pattern Rows = ");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
for (int j = i; j > 0; j--) {
System.out.print(" ");
}
if (i == 1 || i == rows) {
for (int k = 1; k <= rows; k++) {
System.out.print("* ");
}
}
else {
for (int k = 1; k <= rows; k++) {
if (k == 1 || k == rows) {
System.out.print("* ");
} else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
Output
Enter Hollow Mirrored Rhombus Pattern Rows = 12
* * * * * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * * * * *
Java Program to Print Rectangle Star Pattern
For more information on the Java Rectangle of Stars pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
int rows, columns;
sc = new Scanner(System.in);
System.out.print("Enter Number of Rows : ");
rows = sc.nextInt();
System.out.print("Enter Number of Columns : ");
columns = sc.nextInt();
for(int i = 1; i <= rows; i++)
{
for(int j = 1; j <= columns; j++)
{
System.out.print("* ");
}
System.out.print("\n");
}
}
}
Output
Enter Number of Rows : 10
Enter Number of Columns : 15
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
Hollow Rectangle Star Pattern
For more information on the Java Program to Print the Hollow Rectangle Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Hollow Rectangle Rows & Columns = ");
int rows = sc.nextInt();
int columns = sc.nextInt();
for (int i = 0; i < rows; i++ )
{
for (int j = 0 ; j < columns; j++ )
{
if (i == 0 || i == rows - 1 || j == 0 || j == columns - 1) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
Output
Enter Hollow Rectangle Rows & Columns = 9 17
* * * * * * * * * * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * * * * * * * * * *
Java program to Print Sandglass Star Pattern
For more information on the Java Sandglass of Stars pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, rows;
System.out.print("Enter Sandglass Pattern Rows = ");
rows = sc.nextInt();
for (i = 0 ; i <= rows - 1; i++ )
{
result(rows, i);
}
for (i = rows - 1; i >= 0; i-- )
{
result(rows, i);
}
}
public static void result(int rows, int i) {
for (int j = 0 ; j < i; j++ )
{
System.out.print(" ");
}
for(int k = i; k <= rows - 1; k++)
{
System.out.print("* ");
}
System.out.println();
}
}
Output

Hollow Sandglass Pattern of Stars
For more information on the Java Hollow Sandglass Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, rows;
System.out.print("Enter Hollow Sandglass Pattern Rows = ");
rows = sc.nextInt();
for (i = 1 ; i <= rows; i++ )
{
result(rows, i);
}
for (i = rows - 1; i >= 1; i-- )
{
result(rows, i);
}
}
public static void result(int rows, int i) {
for (int j = 1 ; j < i; j++ )
{
System.out.print(" ");
}
for(int k = i; k <= rows; k++)
{
if(i == 1 || k == i || k == rows)
{
System.out.print("* ");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
Output
Enter Hollow Sandglass Pattern Rows = 10
* * * * * * * * * *
* *
* *
* *
* *
* *
* *
* *
* *
*
* *
* *
* *
* *
* *
* *
* *
* *
* * * * * * * * * *
Remaining Java Star Pattern Programs
The following examples print the different shapes of star patterns.
Left Arrow Star Pattern
For more information on the Java Program to Print the Left Arrow Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, j;
System.out.print("Enter Left Arrow Pattern Rows = ");
int rows = sc.nextInt();
for (i = 1; i <= rows; i++) {
for (j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (j = i; j <= rows; j++) {
System.out.print("*");
}
System.out.println();
}
for (i = 1; i < rows; i++) {
for (j = 0; j < i; j++) {
System.out.print(" ");
}
for (j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
Output
Enter Left Arrow Pattern Rows = 9
*********
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
*********
Right Arrow Star Pattern
For more information on Printing the Java Right Arrow Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, j;
System.out.print("Please Enter Right Arrow Pattern Rows = ");
int rows = sc.nextInt();
for (i = 0; i < rows; i++) {
for (j = 0; j < rows; j++) {
if (j < i) {
System.out.print(" ");
} else {
System.out.print("*");
}
}
System.out.println();
}
for (i = 2; i <= rows; i++) {
for (j = 0; j < rows; j++) {
if (j < rows - i) {
System.out.print(" ");
} else {
System.out.print("*");
}
}
System.out.println();
}
}
}
Output
Please Enter Right Arrow Pattern Rows = 8
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
Plus (+) Star Pattern
For more information on the Java Program to Print Plus Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Please Enter Plus Pattern Rows = ");
int rows = sc.nextInt();
for (int i = 1 ; i <= rows * 2 - 1; i++ )
{
if (i != rows)
{
for (int j = 1 ; j <= rows; j++ )
{
if(j == rows) {
System.out.print("*");
}
System.out.print(" ");
}
}
else
{
for (int k = 1 ; k <= rows * 2 - 1; k++ )
{
System.out.print("*");
}
}
System.out.println();
}
}
}
Output
Please Enter Plus Pattern Rows = 7
*
*
*
*
*
*
*************
*
*
*
*
*
*
Java Program to Print V Star Pattern
For more information on Java Printing V Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter V Shape Star Pattern Rows = ");
int rw = sc.nextInt();
for (int i = 1; i <= rw; i++ )
{
printItems(rw, i);
for (int k = 1 ; k <= 2 * (rw - i); k++ )
{
System.out.print(" ");
}
printItems(rw, i);
System.out.println();
}
}
public static void printItems(int rw, int i) {
for (int j = 1 ; j <= i; j++ )
{
System.out.print("*");
}
}
}
Output
Enter V Shape Star Pattern Rows = 12
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
******** ********
********* *********
********** **********
*********** ***********
************************
Inverted V Star Pattern
For more information on the Java Program to Print the Inverted V Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Inverted V Shape Star Pattern Rows = ");
int rw = sc.nextInt();
for (int i = rw; i >= 1; i-- )
{
printItems(rw, i);
for (int k = 1 ; k <= 2 * (rw - i); k++ )
{
System.out.print(" ");
}
printItems(rw, i);
System.out.println();
}
}
public static void printItems(int rw, int i) {
for (int j = 1 ; j <= i; j++ )
{
System.out.print("*");
}
}
}
Output
Enter Inverted V Shape Star Pattern Rows = 10
********************
********* *********
******** ********
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
H Star Pattern
For more information on Printing Java H Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, j, k, l;
System.out.print("Please Enter H Pattern Rows = ");
int rw = sc.nextInt();
for (i = 1; i <= rw; i++) {
for (j = 1; j <= i; j++) {
System.out.print("*");
}
for (k = i * 2; k <= rw * 2 - 1; k++) {
System.out.print(" ");
}
for (l = 1; l <= i; l++) {
System.out.print("*");
}
System.out.println();
}
for (i = 1; i <= rw - 1; i++) {
for (j = rw - 1; j >= i; j--) {
System.out.print("*");
}
for (k = 1; k <= i * 2; k++) {
System.out.print(" ");
}
for (l = rw - 1; l >= i; l--) {
System.out.print("*");
}
System.out.println();
}
}
}
Output
Please Enter H Pattern Rows = 8
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
****************
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
W Star Pattern
For more information on Printing Java W Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter W Shape Star Pattern Rows = ");
int rw = sc.nextInt();
for(int i = 0; i < rw; i++)
{
printStars(i + 1);
printSpaces(rw - i - 1);
printStars(rw - i + 1);
printSpaces(2 * i);
printStars(rw - i);
printSpaces(rw - i - 1);
printStars(i + 1);
System.out.println();
}
}
public static void printStars(int rw)
{
for (int i = 0; i < rw; ++i)
{
System.out.print("*");
}
}
public static void printSpaces(int rw)
{
for (int i = 0; i < rw; ++i )
{
System.out.print(" ");
}
}
}
Output
Enter W Shape Star Pattern Rows = 7
* *************** *
** ******* ****** **
*** ****** ***** ***
**** ***** **** ****
***** **** *** *****
****** *** ** ******
********* ********
X Star Pattern
For more information on Printing Java X Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Please Enter X Pattern Rows = ");
int rw = sc.nextInt();
int k = rw * 2 - 1;
for (int i = 1 ; i <= k; i++ )
{
for (int j = 1 ; j <= k; j++ )
{
if(j == i || j == k - i + 1)
{
System.out.print("*");
}
System.out.print(" ");
}
System.out.println();
}
}
}
Output
Please Enter X Pattern Rows = 8
* *
* *
* *
* *
* *
* *
* *
*
* *
* *
* *
* *
* *
* *
* *
Java Program to print 8 Star Pattern
For more information on the Java Program to Print 8 Star Pattern.
import java.util.Scanner;
public class Example {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Please Enter 8 Pattern Rows = ");
int rw = sc.nextInt();
for (int i = 1; i <= rw * 2 - 1; i++)
{
if (i == 1 || i == rw || i == rw * 2 - 1)
{
for (int j = 1; j <= rw; j++)
{
if (j == 1 || j == rw) {
System.out.print(" ");
}
else {
System.out.print("*");
}
}
}
else
{
for (int k = 1; k <= rw; k++)
{
if (k == 1 || k == rw) {
System.out.print("*");
}
else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
Output
Please Enter 8 Pattern Rows = 6
****
* *
* *
* *
* *
****
* *
* *
* *
* *
****