/**
*
*/
/**
* @author dingtang
* @version 1.0
*
*/
public class Pyramid {
/**
* 主方法:我是法老
*
* @param args
*/
public static void main(String[] args) {
int high = 10;// 输入金字塔的高度;
int base = high * 2 - 1;
// 塔尖
for (int i = 0; i < high; i++) {
System.out.print(" ");
}
System.out.println("*");
// 腰,三围比较恐怖
/*
* 空心的: for (int i = 1; i < (high-1); i++) { for (int j = 0; j < high+i;
* j++) { if (j == (high-i)) { System.out.print("*"); } else {
* System.out.print(" "); } } System.out.println("*"); } //底座,更加让人郁闷!
* System.out.print(" "); for (int i = 1; i <= base; i++){
* System.out.print("*"); }
*/
// 实心的
for (int i = 1; i < (high - 1); i++) {
for (int j = 0; j < high + i; j++) {
if (j < (high - i)) {
System.out.print(" ");
} else {
System.out.print("*");
}
}
System.out.println("*");
}
}
}
画个实心的金字塔
最新推荐文章于 2024-09-11 15:27:41 发布
1405

被折叠的 条评论
为什么被折叠?



