-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_Triangle_Border.java
More file actions
39 lines (25 loc) · 884 Bytes
/
String_Triangle_Border.java
File metadata and controls
39 lines (25 loc) · 884 Bytes
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
39
// Enter a string with string length as multiples of 3 to see the magic
import java.util.*;
import java.lang.String;
class StringTrianglePattern{
public static void main(String[] args) {
String s = new Scanner(System.in).next();
int ods = s.length()/3;
int h=0, t=s.length()-1;
int i=ods-1;
System.out.println("-".repeat(ods)+s.charAt(h++));
ods--;
int ids=1;
while(i>0){
System.out.println("-".repeat(ods)+s.charAt(t--)+"-".repeat(ids)+s.charAt(h++));
ids+=2;
ods--;
i--;
}
StringBuilder sb = new StringBuilder("");
while(h<=t){
sb.append(s.charAt(h++)+"-");
}
System.out.println(sb.reverse().substring(1));
}
}