Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Star Patterns #264

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Java/examples/Patterns/Pattern1.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
18 changes: 18 additions & 0 deletions Java/examples/Patterns/Pattern2.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
20 changes: 20 additions & 0 deletions Java/examples/Patterns/Pattern3.java
Original file line number Diff line number Diff line change
@@ -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--;
}
}
}
20 changes: 20 additions & 0 deletions Java/examples/Patterns/Pattern4.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
30 changes: 30 additions & 0 deletions Java/examples/Patterns/Pattern5.java
Original file line number Diff line number Diff line change
@@ -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<n ; k++){
System.out.print("*");
}
n--;
}
System.out.println();
}
}
}
23 changes: 23 additions & 0 deletions Java/examples/Patterns/Pattern6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* *
**
***
****
*****

*/
public class Pattern6 {
public static void main(String[] args) {
int n = 5;
int spaces= 4;
for (int i = 1; i<=5; i++){
for(int j = 1; j<= spaces ; j++){
System.out.print(" ");
}
for (int k = 1; k<=i ; k++){
System.out.print("*");
}
spaces--;
System.out.println();
}
}
}
20 changes: 20 additions & 0 deletions Java/examples/Patterns/Pattern7.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/* *****
****
***
**
*
*/
public class Pattern7 {
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("*");
}
n--;
System.out.println();
}
}
}

25 changes: 25 additions & 0 deletions Java/examples/Patterns/Pattern8.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* *
***
*****
*******
*********

*/
public class Pattern8 {
public static void main(String[] args) {
int n = 5;
int m = 1;
int space = 4;
for(int i = 1 ; i<=n ; i++){
for(int j = 1 ; j<=space ; j++){
System.out.print(" ");
}
for (int k = 1 ; k<=m ; k++){
System.out.print("*");
}
space--;
m=m+2;
System.out.println();
}
}
}
Loading