打印三角形
package test;
public class 打印三角形 {
public static void main(String[] args) {
for (int i = 1;i<=5;i++){//先赋值一个变量,确定其行数
for (int f = 5;f>i;f--){//在每行中确定空白数
System.out.print(" ");
}
for (int f = 0;f<i;f++){//在每行中确定字符数
System.out.print("*");
}
for (int f = 0;f+1<i;f++){//打印另一半
System.out.print("*");
}
System.out.println();
}
}
}

浙公网安备 33010602011771号