java金字塔怎么打印出来?打印在控制台?哪位大侠告诉,要代码!!!!!!谢谢!!!!!!!
[code="java"]package io;
import java.util.Arrays;
/**
打印一个字符组成的金字塔
*/
public class Pyramid {
// 程序入口
public static void main(String[] args) {
printPyramid(21, '*');
}
/**
@param ch 组成金字塔的字符
*/
private static void printPyramid(int bottom_width, char ch) {
if (bottom_width < 1 || bottom_width % 2 == 0) {
throw new IllegalArgumentException();
}
int height = bottom_width / 2 + 1; // 金字塔的高度
for (int i = 0; i < height; i++) {
int width = i * 2 + 1; // 本层的宽度
System.out.println(getLevel(bottom_width, width, ch));
}
}
/**
/**
你试试,是这样的需求不?
[code="java"]呵呵,客气[/code]
[code="java"]503229799加吧,QQ聊[/code]