public static void main(String[] args) {
printX(10, 4,false);;
}
/**
*
*
@param rows 要输出的行数
* @param startingNumber 第一行多少颗星
* @param positive 正的输出还是倒着输出
*/
public static void printX(int rows ,int startingNumber,boolean positive){
if(rows <= 0 || startingNumber <= 0){
System.out.println("请填写参数(rows:要输出的行数,startingNumber:第一行多少颗星)");
}
int temNumber = 0;//星星的数目
int temKong = 0;//每一行空格的数目
for (int i = 0; i < rows; i++) {
if(positive){
temKong = rows - 1 - i;
temNumber = startingNumber + i * 2;
}else{
temKong = i;
temNumber = (rows - 1- i) * 2 + startingNumber;
}
StringBuffer sb = new StringBuffer();
for (int m = 0; m < temKong; m++) {
sb.append(" ");
}
for (int k = 0; k < temNumber; k++) {
sb.append("*");
}
System.out.println(sb);
}
}