用*画两种三角形:
1:
******
*****
****
***
**
*
2:
*
**
***
****
*****
******
------解决方案--------------------
- Java code
public class Test { public static void main(String[] args) { char a = '*'; int num = 6; for (int i = 0; i < num; i ++){ for (int j = i; j > 0 ; j --) { System.out.print(' '); } for (int k = num - i; k > 0 ; k --){ System.out.print(a); } System.out.println(); } System.out.println(); for (int i = num - 1; i >= 0; i --){ for (int j = i; j > 0 ; j --) { System.out.print(' '); } for (int k = num - i; k > 0 ; k --){ System.out.print(a); } System.out.println(); } }}
------解决方案--------------------
- Java code
public class Trangle2 { public static void main(String[] args) { String b[]=new String[6]; String s[]=new String[6]; String blank=""; String star="*"; for(int i=0;i<6;i++){ b[i]=blank; blank+=" "; s[i]=star; star+="*"; } for(int i=0;i<6;i++){ System.out.println(b[i]+s[5-i]); } }}