Skip to content

Commit 57bda1a

Browse files
Java pattern programs added
1 parent 57d1f71 commit 57bda1a

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

ReversedPyramid.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.Scanner;
2+
public class ReversedPyramid{
3+
public static void main(String[] args){
4+
Scanner in = new Scanner(System.in);
5+
System.out.println("Please enter the number of rows you want to print: ");
6+
int r = in.nextInt();
7+
for (int i= 0; i<= r-1 ; i++){
8+
for(int j=0; j<=i; j++){
9+
System.out.print(" ");
10+
}
11+
for(int k=0; k<=r-1-i; k++){
12+
System.out.print("*" + " ");
13+
}
14+
System.out.println();
15+
}
16+
in.close();
17+
}
18+
}

SandglassPattern.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Scanner;
2+
public class SandglassPattern{
3+
public static void main(String[] args){
4+
Scanner in = new Scanner(System.in);
5+
System.out.println("Please enter the number of rows you want to print: ");
6+
int r = in.nextInt();
7+
for(int i=0; i<=r-1 ; i++){
8+
for(int j=0; j<i; j++){
9+
System.out.print(" ");
10+
}
11+
for(int k=i; k<=r-1; k++){
12+
System.out.print("*" + " ");
13+
}
14+
System.out.println("");
15+
}
16+
for(int i=r-1; i>=0; i--){
17+
for(int j=0; j<i ;j++){
18+
System.out.print(" ");
19+
}
20+
for(int k=i; k<=r-1; k++){
21+
System.out.print("*" + " ");
22+
}
23+
System.out.println("");
24+
}
25+
in.close();
26+
}
27+
}

0 commit comments

Comments
 (0)