-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern-5.java
38 lines (28 loc) · 1001 Bytes
/
pattern-5.java
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
36
37
38
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt(); // n should be odd always
int l = n/2 + 1; // dividing pattern to two halves
// for upper half
for(int i=1; i<=l; i++){
// printing space first
for(int j=1; j<=l-i; j++)
System.out.print("\t");
// printing stars now
for(int k=1; k<=2*i-1; k++)
System.out.print("*\t");
System.out.println();
}
// for lower half
for(int i=l-1; i>=1; i--){
// printing space first
for(int j=1; j<=l-i; j++)
System.out.print("\t");
// printing stars now
for(int k=1; k<=2*i-1; k++)
System.out.print("*\t");
System.out.println();
}
}
}