java基础
怎么输出如下的图型:
*
* *
* * *
* * * *
[解决办法]
代码如下
public class TriangleTest {
public static void printTriangle(int n) {
for (int i = 1; i <= n; i++) {
for (int j = n - i; j > 0; j--) {
System.out.print(" ");
}
for (int k = 1; k < i; k++) {
System.out.print("* ");
}
System.out.println("*");
}
}
/**
* @param args
*/
public static void main(String[] args) {
TriangleTest.printTriangle(4);
}
}