Multiple loops of a Java looping statement
The structure of a loop body that contains a looping statement is called a multiple loop . Three loop statements can be nested within themselves or nested within each other, the most common is the double cycle . In a double loop, the outer loop executes once, and the inner loop executes a circle.
as follows: 650) this.width=650; "src=" http://img.mukewang.com/536c53110001b2a304920260.jpg "/>
For example: use * to print rectangles:
650) this.width=650; "src=" http://img.mukewang.com/536c5253000181a900810058.jpg "/>
Implementation code: 650) this.width=650; "src=" http://img.mukewang.com/536c549d0001381003560206.jpg "/>
Execution Flow: When i = 1 o'clock, the outer loop condition is established, enters the inner loop, and begins to print the first line of content. At this point, J starts at 1, loops 8 times, wraps at the end of the inner loop, and achieves the output of the first row of 8 *. Next, return the outer loop I to 2, prepare to print the next line, and so on, until the rectangle is finished printing.
Code:
public class Helloworld {
public static void Main (string[] args) {
System.out.println ("Print right triangle");
Outer loop control Number of rows
for (int i = 1; i<=3;i++) {
Inner Loop controls the * numbers per line
The maximum value of the inner loop variable is equal to the value of the outer loop variable
for (int j = 1; j<=i;j++) {
System.out.print ("*");
}
Line wrapping after each line is printed
System.out.println ();
}
}
}
Operation Result:
Print Right Triangle
*
**
***
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547788
Java Basics---Multiple loops of Java looping statements (27)