-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathDiamondPattern
35 lines (28 loc) · 963 Bytes
/
DiamondPattern
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
public class DiamondPattern {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of rows needed to print the pattern ");
int rows = scanner.nextInt();
System.out.println("## Printing the pattern ##");
for (int i=1; i<=rows; i++) {
for (int j=rows; j>i; j--) {
System.out.print(" ");
}
for (int k=1; k<=(i * 2) -1; k++){
System.out.print("*");
}
System.out.println();
}
for (int i=rows-1; i>=1; i--) {
for (int j=rows-1; j>=i; j--) {
System.out.print(" ");
}
for (int k=1; k<=(i * 2) -1; k++) {
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}