JAVA
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
import java.util.*;
public class BillDashTriangle
{
public static int n = 7;
public static String dots = "..........";
public static int dd = dots.length(); // dd = 4*(4+1)/2
public static String dash = "------------------------------------";
public static int dl = dash.length(); // dl >= n*(n+1)/2
public static void main(String[] args) {
for(int i=2-n; i<=n-2; i++){
int j = n - 1 - (i>0?i:-i);
int k = (j*(j+1))/2;
if(j<=4){
System.out.println(dots.substring(dd-k));
}
else{
System.out.println(dash.substring(dl-k));
}
}
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run