First, the statement
1.1. Conditional Statement 1.1.1 If statement
1.1.2 Branch Statement (switch statement)
1.2. Loop statement 1.2.1 For Loop statement
Learn to draw memory analysis diagram analysis of other people write the program, so it is easy to analyze the law, analysis of the law also understand the other people's algorithm, it is easy to read other people's program.
in-memory parsingresult=1! +2! ...+10! The algorithm
After analysis to I equals 3, basically has obtained the law, this procedure calculates is: the result = 1!+2!+3!...... +10!.
As you can see, it is helpful to know how to draw memory to analyze programs to understand other people's programs. When you read someone else's program, when you find it difficult to read, you draw memory analysis.
The best way to learn about other people's algorithms is to analyze the programs that others write, and analyze the process of combining memory analysis with the best practices.
1.2.2 While loop and do while loops
1.2.3 Break and Continue statements
Second, the method
When the method executes to the return statement, the execution of the method ends, and the method can have a return value, but it can be used without the return value . method is first defined before it can be called.
1 Public classtestmethod{2 Public Static voidMain (String args[]) {3m ();4 M1 (3); 5 m2 (2,3); 6inti = m3 (4,5); 7System.out.println (i);8 } 9//The following definitions are static methods, and static methods can be called directly inside the main () method.10 Public Static voidm () {System.out.println ("hello!");System.out.println ("Aloof Wolf");13 }14 15 Public Static voidM1 (inti) {16if(i==5){17return;18 }19System.out.println (i);20 }21 22 Public Static voidM2 (intIintj) {System.out.println (i+j);24 }25 26 Public Static intM3 (intIintj) {27returni+J;28 }29}
ThreeScope of the variable
The scope of the variable is only valid for "{}", and it doesn't work if the "{}" is out.
FourRecursive invocation
Recursion: a call to itself within a method is called a recursive
The entire method executes in memory as shown in the procedure:
Example: Using recursion to calculate the number of the 5th Fibonacci sequence
1/*calculate the number of the 5th Fibonacci sequence*/2/*3 Fibonacci Sequence features: F (1) =1,f (2) =1,f (3) =f (1) +f (2), f (4) = (F2) + (F3) ... In turn. 4 that is, the last number is equal to the sum of the first two numbers, such a sequence is the Fibonacci sequence. 5*/6/*7 Calculation of 8 using recursive call method*/9 Public classfab{10 Public Static voidMain (String args[]) {System.out.println (F (5));12 }13 14 Public Static intFintN) {15if(n==1| | n==2){16return1;17}Else{18returnF (n-1) +f (n-2);19 }20 }21}
The entire in-memory execution process is shown in
Fiveprocess of program execution
Basic Java Learning Summary-BASIC Syntax 2