Topics
Introduction
In this article, I have explained the list of all Star (*) pattern programs in java programming language. In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability.
Star pattern : 1
*
**
***
****
*****
class StarTriangle { public static void main(String[] args) { int i, j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern : 2
class StarTriangle { public static void main(String[] args) { int i, j, k; for (i = 5; i >= 1; i--) { for (j = 1; j < i; j++) { System.out.print(" "); } for (k = 5; k >= i; k--) { System.out.print("*"); } System.out.println(); } } }
Star pattern : 3
*****
****
***
**
*
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 5; i >= 1; i--) { for (j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern : 4
class StarTriangle { public static void main(String[] args) { int i, j, k; for(i=5;i>=1;i--) { for(j=5;j>i;j--) { System.out.print(" "); } for(k=1;k<=i;k++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern : 5
*****
*****
*****
*****
*****
class StarTriangle { public static void main(String[] args) { int i, j; for(i=1; i<=5; i++) { for(j=1; j<=5; j++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern : 6
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j < i; j++) { System.out.print(" "); } for (j = 1; j <= 5; j++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern 7
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) { if (j == 1 || j == i || i == 5) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(""); } } }
Star pattern 8
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) { if (j == 1 || j == i || i == 5) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(""); } } }
Star pattern 9
class StarTriangle { public static void main(String[] args) { int i, j, k; for (i = 1; i <= 5; i++) { for (j = i; j < 5; j++) { System.out.print(" "); } for (k = 1; k < (i * 2); k++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern 10
class StarTriangle { public static void main(String[] args) { int i, j, k; for (i = 5; i >= 1; i--) { for (j = 5; j > i; j--) { System.out.print(" "); } for (k = 1; k < (i * 2); k++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern 11
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = i; j < 5; j++) { System.out.print(" "); } for (j = 1; j <= (2 * i - 1); j++) { if (i == 5 || j == 1 || j == (2 * i - 1)) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(""); } }
Star pattern 12
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 5; i >= 1; i--) { for (j = i; j < 5; j++) { System.out.print(" "); } for (j = 1; j <= (2 * i - 1); j++) { if (i == 5 || j == 1 || j == (2 * i - 1)) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(""); } }
Star pattern 13
*
**
***
****
*****
****
***
**
*
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(""); } for (i = 5; i >= 1; i--) { for (j = 1; j < i; j++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern 14
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = i; j < 5; j++) { System.out.print(" "); } for (j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(""); } for (i = 5; i >= 1; i--) { for (j = i; j <= 5; j++) { System.out.print(" "); } for (j = 1; j < i; j++) { System.out.print("*"); } System.out.println(""); } }
Star pattern 15
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = i; j < 5; j++) { System.out.print(" "); } for (j = 1; j <= (2 * i - 1); j++) { System.out.print("*"); } System.out.println(""); } for (i = 5; i >= 1; i--) { for (j = i; j <= 5; j++) { System.out.print(" "); } for (j = 2; j < (2 * i - 1); j++) { System.out.print("*"); } System.out.println(""); } } }
Star pattern 16
class StarTriangle { public static void main(String[] args) { int i, j; for (i = 1; i <= 5; i++) { for (j = 5; j > i; j--) { System.out.print(" "); } System.out.print("*"); for (j = 1; j < (i - 1) * 2; j++) { System.out.print(" "); } if (i == 1) System.out.println(""); else System.out.println("*"); } for (i = 4; i >= 1; i--) { for (j = 5; j > i; j--) { System.out.print(" "); } System.out.print("*"); for (j = 1; j < (i - 1) * 2; j++) { System.out.print(" "); } if (i == 1) System.out.println(""); else System.out.println("*"); } } }