/*
需求:打印等边三角形(若int line = 4,打印图形如下)
*
* *
* * *
* * * *
*/
public static void printStriangle(int line){
for (int i = 1;i <= line ;i++ ) {
for (int m = 0;m < line - i ;m++ ) { //各行前面需要通过空格占位
System.out.print(" ");
}
for (int j = 1;j <= i;j++ ) { //第几行就输出几个星星
System.out.print("* ");
}
System.out.println(); //换到下一行输出
}
} |
|