Home »
Java Programs
Java program to print Pattern of Stars
This section contains programs on Pattern of Stars, these programs will print different pattern of star series.
Pattern of Series Programs in Java
Program 1# Java program to print following pattern of series:
*
* *
* * *
* * * *
* * * * *
public class PrintPattern {
public static void main(String args[]) {
int space = 4;
for (int i = 1; i <= 5; i++) {
//print spaces
for (int j = 1; j <= space; j++)
System.out.print(" ");
//print stars
for (int j = 1; j <= i; j++)
System.out.print("* ");
//print new line
System.out.println();
space--;
}
}
}
Program 2# Java program to print following pattern of series:
* * * * *
* * * *
* * *
* *
*
public class PrintPattern {
public static void main(String args[]) {
int space = 0;
for (int i = 5; i >= 1; i--) {
//print spaces
for (int j = 1; j <= space; j++)
System.out.print(" ");
//print stars
for (int j = 1; j <= i; j++)
System.out.print("* ");
//print new line
System.out.println();
space++;
}
}
}
Program 3# Java program to print following pattern of series:
* *
** **
*** ***
**** ****
**********
public class PrintPattern {
public static void main(String args[]) {
int space = 8;
for (int i = 1; i <= 5; i++) {
//print first part of the row
for (int j = 1; j <= i; j++)
System.out.print("*");
//print space
for (int j = 1; j <= space; j++)
System.out.print(" ");
//print second part of the row
for (int j = 1; j <= i; j++)
System.out.print("*");
//print new lint
System.out.println();
space = space - 2;
}
}
}
Program 4# Java program to print following pattern of series:
**********
**** ****
*** ***
** **
* *
public class PrintPattern {
public static void main(String args[]) {
int space = 0;
for (int i = 5; i >= 1; i--) {
//print first part of the row
for (int j = i; j >= 1; j--)
System.out.print("*");
//print space
for (int j = 1; j <= space; j++)
System.out.print(" ");
//print second part of the row
for (int j = i; j >= 1; j--)
System.out.print("*");
//print new lint
System.out.println();
space = space + 2;
}
}
}
Program 5# Java program to print following pattern of series:
**********
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
**********
public class PrintPattern {
public static void main(String args[]) {
int space = 0;
for (int i = 5; i >= 1; i--) {
//print first part of the row
for (int j = i; j >= 1; j--)
System.out.print("*");
//print space
for (int j = 1; j <= space; j++)
System.out.print(" ");
//print second part of the row
for (int j = i; j >= 1; j--)
System.out.print("*");
//print new lint
System.out.println();
space = space + 2;
}
space = 8;
for (int i = 1; i <= 5; i++) {
//print first part of the row
for (int j = 1; j <= i; j++)
System.out.print("*");
//print space
for (int j = 1; j <= space; j++)
System.out.print(" ");
//print second part of the row
for (int j = 1; j <= i; j++)
System.out.print("*");
//print new lint
System.out.println();
space = space - 2;
}
}
}