-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpider_Pattern.java
More file actions
36 lines (25 loc) · 1.03 KB
/
Spider_Pattern.java
File metadata and controls
36 lines (25 loc) · 1.03 KB
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
//Note: This solution didnot pass all test cases on the day of dt
//However it works under no space cases.
import java.util.*;
public class Main {
public static void main(String[] args) {
int n = new Scanner(System.in).nextInt();
int pi=n-1, eds=0, mds=1 + (n-4)*2;
System.out.println("|".repeat(pi--) + "* ".repeat(n));
for(int i=0; i<n-2; i++){
if(mds<0) mds=0;
System.out.println("|".repeat(pi--)+"* "+"-".repeat(eds)+" * " +
"-".repeat(mds)+" * "+ "-".repeat(eds)+" *");
eds++;
mds-=2;
}
System.out.println("* ".repeat(2*n-1));
mds=0;
for(int i=0; i<n-2; i++){
eds--;
mds += (i==0) ? 0 : (i==1) ? 1 : 2;
System.out.println("|".repeat(++pi)+ "* " + "-".repeat(eds)+" * "+ "-".repeat(mds) +" * "+"-".repeat(eds)+" * ");
}
System.out.println("|".repeat(++pi) + "* ".repeat(n));
}
}