Skip to content

Commit

Permalink
Merge pull request #649 from vijayv18/star-patterns-java
Browse files Browse the repository at this point in the history
Star patterns java
  • Loading branch information
mergify[bot] authored Oct 20, 2023
2 parents a64a858 + 6c5ba3e commit 644f1c1
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Java/Star Patterns/StarPattern16.java
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.
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
*/


50 changes: 50 additions & 0 deletions Java/Star Patterns/StarPattern17.java
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.
* *
* * * *
* * * * * *
* * * * * * *
* * * * * *
* * * *
* *
*/

41 changes: 41 additions & 0 deletions Java/Star Patterns/StarPattern18.java
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.
*
* *
* * *
* * * *
* * *
* *
*
*/
35 changes: 35 additions & 0 deletions Java/Star Patterns/StarPattern19.java
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.
* * * *
* * *
* *
*
* *
* * *
* * * *
*/

32 changes: 32 additions & 0 deletions Java/Star Patterns/StarPattern20.java
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.
*
* *
* *
* *
* * * * *
*/
33 changes: 33 additions & 0 deletions Java/Star Patterns/StarPattern21.java
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.
* * * * *
* *
* *
* *
*
*/
52 changes: 52 additions & 0 deletions Java/Star Patterns/StarPattern22.java
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.
* * * *
* *
* *
*
* *
* *
* * * *
*/


50 changes: 50 additions & 0 deletions Java/Star Patterns/StarPattern23.java
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.
*
* *
* *
* *
* *
* *
*
*/


0 comments on commit 644f1c1

Please sign in to comment.