日期:2014-05-20 浏览次数:20664 次
public class Test{
public static void main(String[] args) {
printDengYao(5,9);//打印等腰三角形
}
public static void printDengYao(int yao,int di){
if(di%2==0){
di+=1;
}
for(int i=0;i<yao;i++){
for(int j = 0;j<di/2-i;j++){
System.out.print(" ");
}
for(int k=0;k<=2*i;k++){
System.out.print("*");
}
for(int n = 0;n<2*(di/2-i);n++){
System.out.print(" ");
}
for(int m=0;m<=2*i;m++){
System.out.print("*");
}
System.out.println();
}
}
}
int h = 5;//高度
h--;
int l = 4 * h;
for (int i = 0; i <= h; i++) {
for (int j = 0; j <= l; j++) {
if (j >= h - i && j <= h + i
------解决方案--------------------
j >= 3 * h - i && j <= 3 * h + i) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}