-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAdd_border.java
29 lines (24 loc) · 1.03 KB
/
Add_border.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
import java.util.Arrays;
public class Add_border{
public static void main (String[] args){
String [][] tests = {
{"abc", "ded"},
{"wzy**"},
{"abcde", "fghij", "klmno", "pqrst", "uvwxy"}
};
for(String[] test : tests){
var testString = Arrays.toString(test).replace(",", ",\n ");
var solutionString= Arrays.toString(solution(test)).replace(",", ",\n ");
System.out.format(" Without border:%n %s %n With border:%n %s %n%n%n", testString, solutionString);
}
}
static String[] solution(String[] picture){
String[] solution = new String[picture.length + 2];
for (int i = 0; i < picture.length; i++)
solution[i + 1] = "*" + picture[i] + "*";
String border = "";
for(; border.length() < picture[0].length() + 2; border += '*'){}
solution [0] = solution[solution.length - 1] = border;
return solution;
}
}