要打印的样式:
代码解析一处:cs[i-1]是下标。数组的下标是从0开始的,所以是数组的长度-1
源代码:
public class shuzu3 {
public static void main(String[] args) {
char[] cs = {'A','B','C','D','E','F','G'};
int len = cs.length;
for(int i = 1; i <= len; i++){
for (int j = i; j < len; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2*i-1; j++) {
System.out.print(cs[i-1]+" ");
}
System.out.println();
}
}
}