定义一个char类型的二维数组,并遍历这个数组,使之能打印出如下效果
*
***
*****
*******
*********
***********
*********
******
****
***
*
2 回答
酒木君
TA贡献23条经验 获得超7个赞
@Test public void test0() { // 1 3 5 7 9 11 char[][] arr = {{42}, {42,42,42}, {42,42,42,42,42}, {42,42,42,42,42,42,42}, {42,42,42,42,42,42,42,42,42}, {42,42,42,42,42,42,42,42,42,42,42}}; // 0 1 2 3 4 5 int sum = 2; for(int i = 0; i<arr.length*2; i++) { if(i < arr.length) { for(int j = 0; j<arr[i].length; j++) { System.out.print(arr[i][j]); } }else if(i >= arr.length && i< (arr.length*2)-1) { for(int j = 0; j<arr[i-sum].length; j++) { System.out.print(arr[i-sum][j]); } sum = sum + 2; } System.out.println(); } }
添加回答
举报
0/150
提交
取消