package com.webkfa.test;
public class Test {
public static void main(String[] args){
printTriangle(5);
}
/**
* 等腰三角形
* @param len
*/
public static void printTriangle(int len) {
//原代码地址:http://www.webkfa.com/one7/w498.html
int a = 0;
int b = 0;
for (int i=1; i<=len; i++) {
if (a != (len - i)) {
System.out.print(" ");
a++;
i = i - 1;
} else if (b != (2 * i - 1)) {
System.out.print("*");
b++;
i = i - 1;
} else if (a == (len - i) && b == (2 * i - 1)) {
System.out.println();
a = 0;
b = 0;
}
}
}
}
运行结果
*
***
*****
*******
*********