-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #649 from vijayv18/star-patterns-java
Star patterns java
- Loading branch information
Showing
8 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
public class StarPattern16 { | ||
|
||
public static void main(String[] args) { | ||
int n=5; | ||
for(int i=0;i<n;i++) { | ||
for(int k=0;k<=i;k++) { | ||
System.out.print(" "); | ||
} | ||
for(int j=0;j<n;j++) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
/* | ||
The output for the above program. | ||
* * * * * | ||
* * * * * | ||
* * * * * | ||
* * * * * | ||
* * * * * | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
public class StarPattern17 { | ||
|
||
public static void main(String[] args) { | ||
int n=4; | ||
for(int i=0;i<n-1;i++) { | ||
for(int j=0;j<=i;j++) { | ||
System.out.print("* "); | ||
} | ||
for(int space=1;space<2*(n-1-i);space++) { | ||
System.out.print(" "); | ||
} | ||
for(int k=0;k<=i;k++) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(); | ||
} | ||
for(int i=1;i<(2*n);i++) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(); | ||
for(int i=0;i<n-1;i++) { | ||
for(int j=n-1;j>i;j--) { | ||
System.out.print("* "); | ||
} | ||
for(int space=0;space<=2*i;space++) { | ||
System.out.print(" "); | ||
} | ||
for(int k=n-1;k>i;k--) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/* | ||
The output for the above program. | ||
* * | ||
* * * * | ||
* * * * * * | ||
* * * * * * * | ||
* * * * * * | ||
* * * * | ||
* * | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
public class StarPattern18 { | ||
|
||
public static void main(String[] args) { | ||
int n = 4; | ||
for(int i=0;i<n;i++) { | ||
for(int k=n-1;k>=i;k--) { | ||
System.out.print(" "); | ||
} | ||
for(int j=0;j<=i;j++) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(); | ||
} | ||
n=n-1; | ||
for(int i=0;i<n;i++) { | ||
System.out.print(" "); | ||
for(int k=0;k<=i;k++) { | ||
System.out.print(" "); | ||
} | ||
for(int j=n-1;j>=i;j--) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/* | ||
The output for the above program. | ||
* | ||
* * | ||
* * * | ||
* * * * | ||
* * * | ||
* * | ||
* | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
public class StarPattern19 { | ||
|
||
public static void main(String[] args) { | ||
int n = 4; | ||
for(int i=0;i<n;i++) { | ||
for(int j=n;j>i;j--) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(); | ||
} | ||
for(int i=1;i<n;i++) { | ||
for(int k=0;k<=i;k++) { | ||
System.out.print("* "); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/* | ||
The output for the above program. | ||
* * * * | ||
* * * | ||
* * | ||
* | ||
* * | ||
* * * | ||
* * * * | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class StarPattern20 { | ||
|
||
public static void main(String[] args) { | ||
int n=5; | ||
for(int i=0;i<5;i++) { | ||
for(int j=n-1;j>=i;j--) { | ||
System.out.print(" "); | ||
} | ||
for(int k=0;k<=i;k++) { | ||
if(i==0 || i==n-1 || k==0 || k==i) { | ||
System.out.print("* "); | ||
} else { | ||
System.out.print(" "); | ||
} | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/* | ||
The output for the above program. | ||
* | ||
* * | ||
* * | ||
* * | ||
* * * * * | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
public class StarPattern21 { | ||
|
||
public static void main(String[] args) { | ||
int n=5; | ||
for(int i=0;i<n;i++) { | ||
for(int j=0;j<=i;j++) { | ||
System.out.print(" "); | ||
} | ||
for(int k=n-1;k>=i;k--) { | ||
if(i==0 || i==n-1 || k==n-1 || k==i) { | ||
System.out.print("* "); | ||
} else { | ||
System.out.print(" "); | ||
} | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/* | ||
The output for the above program. | ||
* * * * * | ||
* * | ||
* * | ||
* * | ||
* | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
public class StarPattern22 { | ||
|
||
public static void main(String[] args) { | ||
int n=4; | ||
for(int i=0;i<n;i++) { | ||
for(int j=0;j<=i;j++) { | ||
System.out.print(" "); | ||
} | ||
for(int k=n-1;k>=i;k--) { | ||
if(i==0 || k==n-1 || k==i) { | ||
System.out.print("* "); | ||
} else { | ||
System.out.print(" "); | ||
} | ||
} | ||
System.out.println(); | ||
} | ||
for(int i=1;i<n;i++) { | ||
for(int j=n-1;j>=i;j--) { | ||
System.out.print(" "); | ||
} | ||
for(int k=0;k<=i;k++) { | ||
if(k==0 || k==i || i==n-1) { | ||
System.out.print("* "); | ||
} else { | ||
System.out.print(" "); | ||
} | ||
|
||
} | ||
System.out.println(); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
/* | ||
The output for the above program. | ||
* * * * | ||
* * | ||
* * | ||
* | ||
* * | ||
* * | ||
* * * * | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
public class StarPattern23 { | ||
|
||
public static void main(String[] args) { | ||
int n=4; | ||
for(int i=0;i<n;i++) { | ||
for(int j=n-1;j>=i;j--) { | ||
System.out.print(" "); | ||
} | ||
for(int k=0;k<=i;k++) { | ||
if(i==0 || k==0 || k==i) { | ||
System.out.print("* "); | ||
} else { | ||
System.out.print(" "); | ||
} | ||
} | ||
System.out.println(); | ||
} | ||
for(int i=1;i<n;i++) { | ||
for(int j=0;j<=i;j++) { | ||
System.out.print(" "); | ||
} | ||
for(int k=n-1;k>=i;k--) { | ||
if(k==n-1 || k==i) { | ||
System.out.print("* "); | ||
} else { | ||
System.out.print(" "); | ||
} | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/* | ||
The output for the above program. | ||
* | ||
* * | ||
* * | ||
* * | ||
* * | ||
* * | ||
* | ||
*/ | ||
|
||
|