Java 练习:打印一个三角形
Java 练习:打印一个三角形
- 这里使用的是 For 循环
示例:
package com.shun.struct;
public class TestDemo {
public static void main(String[] args) {
//打印一个三角形
for (int s = 1;s <=5;s++){
for(int a = 5;a >= s;a--){
System.out.print(" ");
}
for (int d = 1;d <= s;d++){
System.out.print("*");
}
for (int f = 1;f < s;f++){
System.out.print("*");
}
System.out.println();
}
/*
输出的结果是:
*
***
*****
*******
*********
*/
}
}