Diamont

in #ita19 days ago

import java.util.*;

class DiamondPrinter {

String repeatAllSegm(int count){
    char [] sb = new char[count];
    Arrays.fill(sb, ' ');
    String result = new String(sb,0, sb.length);
    return result;
}


List<String> printToList(char a) {
    int index = a -'A';
    List<String> result = new ArrayList<>();
    result.add(repeatAllSegm(index) + "A" + repeatAllSegm(index));
    for(char ch = 'B'; ch <= a; ch++){
        int diff = ch -'A';
        String space = repeatAllSegm(index - diff);
        String centralSpace = repeatAllSegm(2 * diff - 1);
        result.add(space + ch + centralSpace + ch + space); 
    }
    for(int i = result.size()-2; i>=0; i--) result.add(result.get(i));
    return result;
}

}