print a Sandclock prttern:
1 2 3 4 5 6 7 8
|
******** ****** **** ** ** **** ****** ********
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
public class { public static void main(String[] args) * 输出如下沙漏状图形: * ******** * ****** * **** * ** * ** * **** * ****** * ******** */ int n = 8; int i , j, k ,m, p; k = n/2; for (i=0; i<=n; i++){ m = k- Math.abs(k-i); p = Math.abs(n - 2 * i); if(p==0){ continue; } for(j=0;j<m;j++){ System.out.print(" "); } for(j=0;j<p;j++){ System.out.print("*"); } System.out.println(); } } }
|
近期评论