java语言如何打印这个图形?有半段代码求指点……

###*
##**
#***
##**
###*
打印它的三行的代码我已经写出来了
for (int i = 1; i <= 3; i++) {
for (int kong =1; kong<=4-i; kong++) {
System.out.print(" ");
}
for (int xing = 1; xing <=i; xing++) {
System.out.print("*");
}
System.out.println();
}
后面二行怎么写也写不出来。求大神指点

3个回答

public class Test{
public static void main(String[] args) {
    // TODO Auto-generated method stub

        int i, j, k;
        for(i = 1; i <= 3; i ++){
            for(j = 0 ; j < 4 - i; j++)
                System.out.print("#");
            for( k= 0 ; k <  i; k++)
                System.out.print("*");
            System.out.print("\n");
        }
        for(i = 1; i < 3; i ++){
            for(j = 0 ; j < i + 1; j++)
                System.out.print("#");
            for( k= 0 ; k < 3 - i; k++)
                System.out.print("*");
            System.out.print("\n");
        }
    }
} 
public class Test{
public static void main(String[] args) {
    // TODO Auto-generated method stub

        int i, j, k;
        for(i = 1; i <= 3; i ++){
            for(j = 0 ; j < 4 - i; j++)
                System.out.print("#");
            for( k= 0 ; k <  i; k++)
                System.out.print("*");
            System.out.print("\n");
        }
        for(i = 1; i < 3; i ++){
            for(j = 0 ; j < i + 1; j++)
                System.out.print("#");
            for( k= 0 ; k < 3 - i; k++)
                System.out.print("*");
            System.out.print("\n");
        }
    }
} 

package com.test;

public class Test {

public static void main(String[] args) {
    int jing = 3;
    int xing = 1;
    int flag = -1;
    for(int i = 0; i < 5; i++){

        for(int j = 0; j < jing; j++){
            System.out.print("#");
        }

        for(int k = 0; k < xing; k++){
            System.out.print("*");
        }

        System.out.println();
        jing = jing + flag;
        xing = xing - flag;

        if(jing == 1 || jing == 3){
            flag = 0 - flag;
        }
    }
}

}

想要多少行都可以了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!