日期:2014-05-20 浏览次数:20937 次
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(); } } }
------解决方案--------------------
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]); } } }