打印出星型金字塔
常数变易法思维
找规律
/*
*
* *
* * *
* * * *
* * * * *
*/
public class ConstantVariation01 {
public static void main(String[] args) {
//用常数变易法找出规律
//k=0 1 2 3 4
//i=9 8 7 6 5 9-k
//j=1 2 3 4 5 k+1
for (int k = 0; k <5; k++) {//定义行数
for (int i = 0; i <9-k ; i++) {
System.out.print(" ");
}
for (int j = 0; j <k+1 ; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}