java用循环编写小树图形

如题所述

public static void main(String[] args) {
    int a = 3;
    int b = 3;
    for (int i = 0; i < 11; i++) {
        for (int j = 0; j < 11; j++) {
            if (b == 11) {
                if (j > 2 && j < 8) {
                    System.out.print("* ");
                } else {
                    System.out.print("  ");
                }
            } else {
                if (j > a && j <= (a + b)) {
                    System.out.print("* ");
                } else {
                    System.out.print("  ");
                }
            }
        }
        System.out.println("");
        if (a != 0) a--;
        if (b != 11) b += 2;
    }
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-10-30
package test;

public class Shu {
public static void main(String[] args) {
for(int i=1; i<=5; i++) {
for(int j=5; j>i; j-- ){
System.out.print(" ");
}
for(int k=i; k<i*3+1; k++) {
System.out.print("*");
}
System.out.println("");
if(i==5){
for(int a=0;a<3;a++){
System.out.println("   *****");
System.out.println("");
}

}
}
}

}

相似回答