Given a rectangular matrix of characters, add a border of asterisks(*) to it.

Example

For

picture = ["abc",
           "ded"]

the output should be

solution(picture) = ["*****",
                     "*abc*",
                     "*ded*",
                     "*****"]

Input/Output

풀이

String[] solution(String[] picture) {
    String [] result = new String [picture.length + 2];
    int length = picture[0].length() + 2;
    
    String stars = "";
    
    for (int i = 0; i < length; i++) {
        stars += "*";
    }
    
    result[0] = stars;
    result[result.length - 1] = stars;
    
    for (int i = 1; i < result.length - 1; i ++) {
        result[i] = "*" + picture[i - 1] + "*";
    }
    
    return result;
}