Java from getting started to mastering 03-Process Control

Source: Internet
Author: User

Three major Process Control
1. Sequential control
2. Branch control
3. Cyclic control

There are three types of branch control
1. Single Branch
if (conditional expression) {
statement;
}
2. Dual Branch
if (conditional expression) {
statement;
}else{
Statement
}
3, multi-branch
if (conditional expression) {
statement;
}else if (conditional expression) {
statement;
}else if (conditional expression) {
statement;
}else{
Statement
}

switch (conditional expression) {
case constant 1:
Span style= "color: #c0c0c0;" > statement 1;
break;
case constant 2:
statement 2;
break;
...

statement n;
break;
default:
statement;
break;
"
//conditional expression data type consistent with the constant type after case;

There are three types of cyclic control
For loop
For (cyclic initial value; loop condition; step) {
Statement
}

While loop
while (loop condition) {

statement;//Loop body
}
While loop is the first judgment, then executes the statement;

Do and loop
do{
statement;//Loop body
}while (cyclic conditions);
The Do While loop is executed first, then judged;

Comprehensive examples
Print the pyramid in the console as follows:

         *
        * * *
      * * *
    *******
  *********
***********
code as follows:

public static void Main (String args[]) {
int lay=7;
for (int i=1;i<=lay;i++) {
for (int k=1;k<=lay-i;k++) {
System.out.print ("");
}
for (int j=1;j<= (i-1) *2-1;j++) {
System.out.print ("*");
}
System.out.println ();
}
}

Java from getting started to mastering 03-Process Control

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.