递归的方法打印菱形
public class Test {
public static void main(String[] args) {
StringBuffer stringBuffer = new StringBuffer("*");
append(0,5,stringBuffer);
delete(0,5,stringBuffer.delete(0,2));
}
public static void append(Integer index,Integer max,StringBuffer s){
if (index<max){
System.out.println(String.format("%"+(max+index)+"s",s));
append(++index,max,s.append("**"));
};
}
public static void delete(Integer index,Integer min,StringBuffer s){
if (min>0){
System.out.println(String.format("%"+(s.delete(0,2).length()+(++index))+"s",s));
delete(index,--min,s);
}
}
}