diff --git a/Java/examples/Patterns/Pattern1.java b/Java/examples/Patterns/Pattern1.java new file mode 100644 index 00000000..0654620c --- /dev/null +++ b/Java/examples/Patterns/Pattern1.java @@ -0,0 +1,18 @@ + /* + ***** + ***** + ***** + ***** + ***** +*/ +public class Pattern1 { + public static void main(String[] args) { + int n = 5; + for(int i = 1 ; i<=n ; i++){ + for(int j = 1 ; j<=n ; j++){ + System.out.print("*"); + } + System.out.println(); + } + } +} \ No newline at end of file diff --git a/Java/examples/Patterns/Pattern2.java b/Java/examples/Patterns/Pattern2.java new file mode 100644 index 00000000..6514ccec --- /dev/null +++ b/Java/examples/Patterns/Pattern2.java @@ -0,0 +1,18 @@ +/* + * + ** + *** + **** + ***** +*/ +public class Pattern2 { + public static void main(String[] args) { + int n = 5; + for (int i = 1; i<=n; i++){ + for (int j = 1; j<= i; j++){ + System.out.print("*"); + } + System.out.println(); + } + } +} diff --git a/Java/examples/Patterns/Pattern3.java b/Java/examples/Patterns/Pattern3.java new file mode 100644 index 00000000..48d5c7df --- /dev/null +++ b/Java/examples/Patterns/Pattern3.java @@ -0,0 +1,20 @@ +/* + ***** + **** + *** + ** + * + + */ +public class Pattern3 { + public static void main(String[] args) { + int n = 5; + for(int i = 1; i<=5 ; i++){ + for(int j = 1; j<=n; j++ ){ + System.out.print("*"); + } + System.out.println(); + n--; + } + } +} diff --git a/Java/examples/Patterns/Pattern4.java b/Java/examples/Patterns/Pattern4.java new file mode 100644 index 00000000..b5505dcb --- /dev/null +++ b/Java/examples/Patterns/Pattern4.java @@ -0,0 +1,20 @@ +/* 1 + 1 2 + 1 2 3 + 1 2 3 4 + 1 2 3 4 5 + + */ +public class Pattern4 { + public static void main(String[] args) { + int n = 5; + for(int i = 1;i<=n; i++){ + int s = 0; + for(int j = 1 ; j<=i; j++){ + System.out.print(s+1); + s++; + } + System.out.println(); + } + } +} diff --git a/Java/examples/Patterns/Pattern5.java b/Java/examples/Patterns/Pattern5.java new file mode 100644 index 00000000..aa436599 --- /dev/null +++ b/Java/examples/Patterns/Pattern5.java @@ -0,0 +1,30 @@ +/* * + ** + *** + **** + ***** + **** + *** + ** + * + + */ +public class Pattern5 { + public static void main(String[] args) { + int n = 5; + for (int i = 1; i<10; i++){ + if (i<=n){ + for(int j =1; j<=i; j++){ + System.out.print("*"); + } + } + else { + for(int k = 1 ; k