打印沙漏

public class sdf {
    public static void main(String[] args) {
        int n = 7;
        int i,j,k,m,p;
        k = n/2+1;
        for (i = 0; i <= n; i++) {
            m = k - Math.abs(i-k);
             p = Math.abs(2*(k-i))-1;
            if(p == -1){
                continue;
            }
            for(j = 0 ; j < m; j ++){
                System.out.print(" ");
            }
            for(j = 0; j < p; j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

原文地址:https://www.cnblogs.com/superws/p/5256673.html