打印等腰三角形
- 第1次推导
public class test9 {
public static void main(String[] args) {
// 行数
int a = 3;
System.out.println();
System.out.print(" ");
System.out.print(" ");
System.out.print("*");
System.out.println();
System.out.print(" ");
System.out.print("*");
System.out.print("*");
System.out.print("*");
System.out.println();
System.out.print("*");
System.out.print("*");
System.out.print("*");
System.out.print("*");
System.out.print("*");
}
}
- 推导过程
public class test {
public static void main(String[] args) {
// 行数
int a = 3;
System.out.println();
for (int i=1; i<=2; i++){
System.out.print(" ");
}
for (int i=1; i<=1; i++){
System.out.print("*");
}
System.out.println();
for (int i=1; i<=1; i++){
System.out.print(" ");
}
for (int i=1; i<=3; i++){
System.out.print("*");
}
System.out.println();
for (int i=1; i<=0; i++){
System.out.print(" ");
}
for (int i=1; i<=5; i++){
System.out.print("*");
}
}
}
- 最后
public class test {
public static void main(String[] args) {
// 行数
int a=5;
int b=1;
for (int j=a; j>=1; j--){
System.out.println();
for (int i=1; i<j; i++){
System.out.print(" ");
}
for (int i=1; i<=b; i++){
System.out.print("*");
}
b+=2;
}
}
}
标签:int,System,案例,循环,println,print,编写,public,out
From: https://www.cnblogs.com/dogleftover/p/17736968.html