Pattern Programming
Pattern Programming

Pattern 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package pattern; public class Pattern1 { public static void main(String[] args) { for(int i=1;i<=5;i++)// this loop executed 5 time it indicate number of row { for(int j=1;j<=5;j++) //it indicate number of column { System.out.print(j); } System.out.println(); } } } |
Pattern 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | package pattern; public class Pattern2 { public static void main(String[] args) { for(int i=1;i<=5;i++) { for(int j=1;j<=5;j++) { System.out.print(i); } System.out.println(); } } } |
Pattern 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package pattern; public class Pattern3 { public static void main(String[] args) { for(int i=1;i<=5;i++) { for(int j=5;j>=1;j--) { System.out.print(j); } System.out.println(); } } } |
Pattern 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package pattern; public class Pattern4 { public static void main(String[] args) { for(int i=5;i>=1;i--) { for(int j=1;j<=5;j++) { System.out.print(i); } System.out.println(); } } } |
Pattern 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package pattern; public class pattern5 { public static void main(String[] args) { for(int i=1;i<=5;i++) { for(int j=1;j<=i;j++) { System.out.print(j); } System.out.println(); } } } |
Pattern 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | package pattern; public class Pattern6 { public static void main(String[] args) { for(int i=1;i<=5;i++) { for(int j=1;j<=i;j++) { System.out.print(i); } System.out.println(); } } } |
Pattern 7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | package pattern; public class Pattern7 { public static void main(String[] args) { for(int i=1;i<=5;i++) { for(int j=1;j<=5;j++) { for(int k=1;k<=j;k++) { System.out.print(k); } System.out.println(""); } } } } |
Pattern 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | package pattern; public class Pattern8 { public static void main(String[] args) { for(int i=0;i<=4;i++) { for(int j=i;j<=4;j++) { System.out.print(" "); } for(int k=0;k<=i;k++) { System.out.print("*"); } System.out.println(); } } } |
Pattern 9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | package pattern; public class Pattern9 { public static void main(String[] args) { for(int i=0;i<=4;i++) { for(int j=i;j<4;j++) { System.out.print(" "); } for(int k=1;k<=(2*i+1);k++) { System.out.print("*"); } System.out.println(); } } } |
Pattern 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | package pattern; public class Pattern10 { public static void main(String[] args) { for(int i=1;i<=5;i++)// this loop executed 5 time it indicate number of row { for(int j=1;j<=5;j++) //it indicate number of column { if(i==j || i+j==6) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } } |