-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMagic_Pattern_20.java
36 lines (34 loc) · 1.01 KB
/
Magic_Pattern_20.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
import java.util.Scanner;
public class Magic_Pattern_20 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n = s.nextInt();
int top = n;
int mspace = -1;
for (int i = 0; i < 2*n-1; i++) {
if (i == 0 || i==2*n-2)
for (int j = 0; j < 2 * n - 1; j++) {
System.out.print("*");
}
else {
for (int j = 0; j < top; j++) {
System.out.print("*");
}
for (int j = 0; j < mspace; j++) {
System.out.print(" ");
}
for (int j = 0; j < top; j++) {
System.out.print("*");
}
}
System.out.println();
if (i >= n - 1) {
top++;
mspace -= 2;
} else {
top--;
mspace += 2;
}
}
}
}