打印三角型
/*
@author Nian
@DateSTest 2022/7/19 20:41
*/
public class Number31 {
public static void main(String[] args) {
//打印如下图形
// *
// * * *
// * * * * *
// * * * * * * *
// * * * * *
// * * *
// *
printTriangle(7);
}
public static void printTriangle(int floors){
if(floors%2!=0){
for (int i = 1; i <= floors; i+=2) {
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
if(i==floors){
int x = floors-2;
for (int j = x; j <=x && j>=1 ; j-=2) {
for (int k = 1; k <= j; k++) {
System.out.print("* ");
}
System.out.println();
}
}
}
}else {
System.out.println("参数必须为单数");
}
}
}