This article has the basic method overloading , The basic idea is as follows :
1. First use for Loop nesting prints a square
2. Modify the loop condition , Decrease the number of small stars in turn
3. Print between stars for Loop print space number , There is an increasing trend .
4. Print double space to eliminate the space after printing stars .
package lesson01;
public class Demo01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
test1();// Method call
}
public static void test1() {// Overloading methods
int row=5;
for(int i=row;i>0;i--) {
for(int k=0;k<row-i;k++) {// Control the number of printed spaces
System.out.print(" ");// Double space
}
for(int j=1;j<=i;j++) {
System.out.print("* ");
}
System.out.println();
}
}
}
Please criticize and correct me , thank you .