编写程序输出下面图形。 * *** ******* *** * 要求编出程序, 并附上程序运行结果截图
package com.part;
import java.util.Scanner;
public class MyTest {
public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=0; n=in.nextInt(); int count=0; count=(int) (Math.pow(2, n/2+1))/2; int i; for(i=1;i<=n/2+1;i++){ for(int j=1;j<=count-Math.pow(2, i-1);j++){ System.out.print(\); } for(int k=1;k<=Math.pow(2, i)-1;k++){ System.out.print(\); } System.out.println(); } for(;i<=n;i++){ for(int j=1;j<=count-Math.pow(2, n-i);j++){ System.out.print(\); } for(int k=1;k<=Math.pow(2, n-i+1)-1;k++) System.out.print(\); System.out.println();
}
}
}
程序运行截图:
相关推荐: