Different patterns print in java,Programs In Java,triangle pattern, pyramid pattern, diamond pattern and many other Pattern which is created by using java.
1.
class star { /* XXXXX XXXX XXX XX X XX XXX XXXX XXXXX */ public static void main(String[] args) { for(int i=1;i<=5;i++) { for(int j=i;j<=5;j++) { System.out.print("X"); } System.out.println(""); for(int o=5;o==i;o++) { for(int m=1;m<=4;m++) { for(int n=m;n<=3;n++) { System.out.print(" "); } for(int l=0;l<=m;l++) { System.out.print("X"); } System.out.println(""); } } for(int k=1;k<=i;k++) { System.out.print(" "); } } } }
2.
class star2 { /* X XXX XXXXX XXXXXXX XXXXXXXXX XXXXXXX XXXXX XXX X */ public static void main(String[] args) { int m=9, y=1; for(int n=1;n<=4;n++) { for(int p=n;p<=4;p++) { System.out.print(" "); } for(int k=1;k<=y;k++) { System.out.print("X"); } for(int l=n;l<=4;l++) { System.out.print(" "); } System.out.println(""); y=y+2; } for(int i=1;i<=5;i++) { for(int j=i;j<=m;j++) { System.out.print("X");} m--; System.out.println(""); for(int k=1;k<=i;k++) { System.out.print(" "); } } } }
3.
class star3 { /* XXXXXXXXXX XXXXXXXX XXXXXX XXXX XX XXXX XXXXXX XXXXXXXX XXXXXXXXXX */ public static void main(String[] args) { int g=10,p=4; for(int i=1;i<=5;i++) { for(int j=i;j<=g;j++) { System.out.print("X"); } System.out.println(""); for(int l=5;l==i;l++) { for(int m=1;m<=4;m++) { for(int n=m;n<=3;n++) { System.out.print(" "); } for(int o=1;o<=p;o++) { System.out.print("X"); } p=p+2; System.out.println(""); } } for(int k=1;k<=i;k++) { System.out.print(" "); } g--; } } }
4.
class star4 { /* XXXXX XXXX XXX XX X XX XXX XXXX XXXXX */ public static void main(String[] args) { int g=2; for(int i=1;i<=5;i++) { for(int j=i;j<=5;j++) { System.out.print("X"); } System.out.println(""); for(int l=5;l==i;l++) { for(int m=1;m<=4;m++) { for(int o=1;o<=4;o++) { System.out.print(" "); } for(int n=1;n<=g;n++) { System.out.print("X"); } System.out.println(""); g++; } } for(int k=1;k<=i;k++) { System.out.print(" "); } } } }
5.
class star5 { /* XXXXXXXXXXX XXXXX XXXXX XXXX XXXX XXX XXX XX XX X X XX XX XXX XXX XXXX XXXX XXXXX XXXXX XXXXXXXXXXX */ public static void main(String[] args) { int g=9,h=1; for(int n=1;n<=11;n++) { System.out.print("X"); } System.out.println(""); for(int p=1;p<=4;p++) { for(int o=p;o<=5;o++) { System.out.print("X"); } for(int q=1;q<=h;q++) { System.out.print(" "); } for(int a=p;a<=5;a++) { System.out.print("X"); } System.out.println(""); h=h+2; } for(int i=1;i<=5;i++) { for(int j=1;j<=i;j++) { System.out.print("X"); } for(int k=1;k<=g;k++) { System.out.print(" "); } for(int l=1;l<=i;l++) { System.out.print("X"); } System.out.println(""); g=g-2; for(int m=-1;m==g;m++) { for(int n=1;n<=11;n++) { System.out.print("X"); } } } } }
6.
class star6 { /* X X X X X X X X X */ public static void main(String[] args) { int m=7; for(int i=1;i<=4;i++) { for(int j=i;j<=i;j++) { System.out.print("X"); } for(int k=1;k<=m;k++) { System.out.print(" "); } for(int l=i;l<=i;l++) { System.out.print("X"); } System.out.println(""); for(int n=1;n<=i;n++) { System.out.print(" "); } m=m-2; } for(int o=-1;o==m;o++) { System.out.print("X");} } }
7.
class star7 { /* * ** *** **** ***** */ public static void main(String[] args) { for(int i=1;i<=5;i++) { for(int j=1;j<=i;j++) { System.out.print("*"); } System.out.println(""); } } }
8.
class star8 { /* ***** **** *** ** * */ public static void main(String[] args) { for(int i=5;i>=0;i--){ for(int j=i;j>0;j--){ System.out.print("*"); } System.out.println(""); } } }
9.
class star9{ /* * ** *** **** ***** */ public static void main(String[] args){ for(int l=0;l<=5;l++){ for(int m=l;m<5;m++){ System.out.print(" "); } for(int n=1;n<=l;n++){ System.out.print("*"); } System.out.println(""); } } }
10.
class star10 { /* ***** **** *** ** * */ public static void main(String[] args) { int a=2,b=2; for(int i=1;i<=5;i++){ for(int j=0;j<=i;j++){ System.out.print(" "); } for(int k=i;k<=5;k++){ System.out.print("*"); } System.out.println(""); } } }
(Visited 3,039 times, 1 visits today)
Written by: