Java Basics---Multiple loops of Java looping statements (27)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.