A. Straight Ladder * Print
First on the result map
Idea: The basic constituent unit of the result diagram is an * number, which is implemented by internal and external for loop, the code is as follows:
1 classDayin2 {3 Public Static voidMain (string[] args)4 {5 for(intx=4;x>=0;x--)6 {7 for(inty=5; (y-x) >0;y--)8 {9System.out.print ("*");Ten } One System.out.println (); A } - } -}
Two. Inverted Ladder printing
Directly on the code:
1 classDayin2 {3 Public Static voidMain (string[] args)4 {5 for(intx=0;x<5;x++)6 {7 for(inty=5; (y-x) >0;y--)8 {9System.out.print ("*");Ten } One System.out.println (); A } - } -}
By adding System.out.println () in the outer loop; To achieve skip.
Summary: It will be found that the outer loop control is the number of rows, the inner loop control is the number of columns (number), then naturally, the outer loop just let it cycle 5 times,
The key point is the loop condition within the loop, adjusting the relationship of the row variable and the column variable to achieve the goal, the advantage will be good.
Java internal and external loop print ladder * number