Process control method

First, the process control classification 

Flow control process structure using three basic structural predetermined programming, namely: a branched structure, cyclic structure and sequence structure.

1, java branched structure divided into two types :

   if conditional branching , is determined not a single type, as long as a branch is executed, the branch is no longer performed behind, and interval may be equivalent, if a large range of

  ② Switch Case , matching the fixed value (shaping / character / Boolean / String (jdk1.7 +) less than compelling not match with string); a single type of determination conditions; (if no break out) after the branch execution, Analyzing performed without down; default may be omitted ( default position may be arbitrary, but not the last time, break can not be omitted; strongly recommended placed at the end, and finally into the default may be omitted BREAK )

2, Java common three cycles while / do while / for, loop structure: the number of cycles for controlling the variable declaration cycling conditions, loop, the iteration change

  ①while first determination condition, the loop body is executed, if the first determination is false, a loop is not performed

  ②do while executed first loop , the determination condition. Minimum executed once. When the while loop / do while the first determination is true, then no difference between two kinds of loop

  ③for  Expression 1 iteration variable initialization, the expression 2 loop condition is determined , if it is to false , the end of the cycle, Expression 3 iterative variation, the function performed {01}

3, the order of the structure, as the name implies, sequentially performs

Two, BREAK and continue

1, break: the end of the current cycle and exits the current loop, break out of the switch can also

2, continue: the loop does not execute a subsequent statement, but not the end of the cycle, is determined to continue cycling conditions (also for loop i ++). continue just the end of this cycle.

Third, the dual circulation

while, dowhile, for can be nested within each other, the outer loop is executed once, the inner layer cyclic performed n times, the entire loop executes m * n times .

Double loop generally can solve a significant problem in the ranks . Inner layer loop control bar, the outer loop line

Fourth, the method

Completion of a particular function and the code can be reused blocks called method (Method). Modifier, return type (mandatory, if no return value shall write void), method name, parameter list, Procedure: accomplish specific functions. If there is a return value, you must have a return statement; if no return value, the default is the last statement return , it can be omitted. RET URN for the end of the process, give control to the call of the method.

In the parameter defined by the method referred to in the form of parameters, referred to as parameters. In the incoming call when the method parameters are called actual parameters , referred to as the argument. Argument -> parameter of the process is passed by value.

The recursive method, the problem to be solved features: ① the problem can be decomposed into a number of layers that are simply sub-problems. consistent sub-problems and their solutions to top issues. ③ solve the problem depends on the sub-layer solution to the problem

Recursive structure comprises two parts: ① recursive end condition. Answer: When not call itself method. If there are no conditions, will fall into an infinite loop.

           ② recursive body. ANSWER: When do I need to call their own methods.

Recursive advantages: simple program

Shortcoming recursive: recursive calls will take up a lot of system stack, memory consumption and more recursive call level more slowly than the speed of circulation in a long time

Recursive Use: Any problem can be solved by recursion can be solved using an iterative; when the recursive method can be more natural reflection of the problem, and easy to understand and debug, and not stressed efficiency, can be used recursively; in the case of high-performance requirements under avoid using recursion, recursive both time consuming and memory.

Fifth, the random number 

Math.random () for generating a random floating point number , which is the range [0,1), the commonly used [m, n] equation: [m, n] => (int) (Math.random () * ( n-m + 1) + m )

Development: Any random integer interval ① [m, n-) => [m, n--. 1] ② (m, n-) => [m +. 1, n--. 1] ③ (m, n-] => [m + 1, n]

Sixth, method overloading 

A class method names the same , the parameter different methods constituting a list method overload . Note: method return values of method overloading and nothing to do.

The method overloaded is determined by: [1] in the same class. [2] The method names the same. [3] the parameter list of the different (type , number, parameters of different types of order ).

Guess you like

Origin www.cnblogs.com/javasan/p/11329824.html