Java Process Control

Source: Internet
Author: User

There is a step to do everything. The first step is what to do, and the second step is what to do... until things are completed. Process control is to arrange and manage such steps. Java Process Control, as its name implies, is to arrange and manage the steps of the Java language.

Java Process Control includes sequence control, condition control, and loop control.

Sequential control means that each statement is executed from start to end in sequence. Conditional Control: select the execution statement based on the conditions. For example, if the condition is true, operation A is executed, or operation A is executed if the condition is true. Otherwise, Operation B is executed. Loop Control, also known as loop control, executes operations in the loop body according to the initial conditions and termination requirements of the loop.

In fact, whether it is various controls, in the final analysis, it is the step-by-step expression of doing things, some are sequential, some are conditional, and some are controlled. In a broad sense, jobs are completed in sequence.

Java's condition control mainly takes the following forms:

1) if (condition) {statement}

2) if (condtion) {statement1} else {statement2}

3) switch (condition) {case condition1: statement1; break; ...... default: statement}

4) combination and nesting of the above forms

Java's main forms of loop control are as follows:

1) while (condtion) {statement}

2) do {statement} while (condtion );

3) for (initialCondition; circleCondition; iterator) {statement}

4) combination and nesting of the above forms

In order to better understand and Understand Java Process Control, simple instance code is compiled separately.

1) The sequence control instance code is as follows:

[Java]
/**
* <P> Titlet: Sequence Control </p>
* <P> Description: a simple example of Sequential Control </p>
* <P> Copyright: Copyright (c) 2012 </p>
* <P> Filename: SequenceDemo. java </p>
* @ Author Wang luqing
* @ Version 1.0
*/
Public class SequenceDemo {
/**
* Method Description: Main Method
* Input parameter: String [] args
* Return type: void
*/
Public static void main (String [] args ){
System. out. println ("\ t my motto ");
System. out. println ("\ t rows are not allowed, Please deny ");
System. out. println ("\ t what you do not want, do not apply to people ");
System. out. println ("\ t has a high capacity, and no desire, just ");
System. out. println ("\ t giving roses, hand fragrance ");
}
}
The running result is as follows:


2) The Conditional Control Code is as follows:

[Java]
/**
* <P> Titlet: condition Control </p>
* <P> Description: a simple example of conditional if control </p>
* <P> Copyright: Copyright (c) 2012 </p>
* <P> Filename: IfDemo. java </p>
* @ Author Wang luqing
* @ Version 1.0
*/
Import java. util .*;
 
Public class IfDemo {
/**
* Method Description: Main Method
* Input parameter: String [] args
* Return type: void
*/
Public static void main (String [] args ){
System. out. println ("Enter your Java evaluation score :");
Repeated scan = new partition (System. in );
Int score = scan. nextInt ();
 
If (score> 80 ){
System. out. println ("persistent efforts ");
}

If (score <= 80 ){
System. out. println ("good learning ");
}
}
The running result is as follows:

Enter your Java evaluation score:

95

Persistent efforts

The above code can also be implemented using other conditions.

3) cyclic control instance code

 

[Html]
/**
* <P> Titlet: cyclic control </p>
* <P> Description: a simple example of for Control </p>
* <P> Copyright: Copyright (c) 2012 </p>
* <P> Filename: ForDemo. java </p>
* @ Author Wang luqing
* @ Version 1.0
*/
Public class ForDemo {
/**
* Method Description: Main Method
* Input parameter: String [] args
* Return type: void
*/
Public static void main (String [] args ){
Int iSum = 0;
Int index;

For (index = 1; index <= 100; index ++ ){
ISum + = index;
}
System. out. println ("1 + 2 +... + 99 + 100 =" + iSum );
}
}
The running result is as follows:

1 + 2 +... + 99 + 100 = 5050
The above code can also be implemented in other forms of loop control.

Summary:

1) Java Process Control reflects the sequence of Java operations. The old saying goes, "There are things at the end and things start at the end. ."

2) When using Java Process Control, you need to find out what to do and how to do it, and then select the appropriate process control implementation.

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.