日期:2014-05-20 浏览次数:20831 次
public class Arryays{ public static void main(String args[]) { int i, j; char a[][] = new char[5][]; a[0] = new char[1]; a[1] = new char[3]; a[2] = new char[5]; a[3] = new char[7]; a[4] = new char[9]; a[0][0] = 'a'; for (i = 0; i < 3; i++) a[1][i] = 'b'; for (i = 0; i < 5; i++) a[2][i] = 'c'; for (i = 0; i < 7; i++) a[3][i] = 'd'; for (i = 0; i < 9; i++) a[4][i] = 'e'; for (i = 0; i < 5; i++) { // 外层循环5次,打印5行字母 for (j = 15 - i; j > 0; j--)//表示每行打印字母前打印的空格数,第一行15个,依次递减 System.out.print(" "); for (j = 0; j <= 2 * i; j++) {//表示每行打印同一字母的个数,和行数相关的规律 System.out.print(a[i][j] + ""); } System.out.println(); } } }