We have written a lot of loops before, because we have to do repetitive actions so that we use the loop to make our code less, easier to write, but the cycle is not easy to maintain, difficult to read, logic once the error, the use of loops can lead to error.
Now let's introduce the concept of a function: a code with a name that can be used by that name.
Note: A: must first be declared, and then called. B: Declaration syntax public static return type function name (formal parameter list) {function Body}
C: When the return type is empty, you do not need to return a value, when the return type is not empty, you need to use the keyword return to return a type with the declaration function return type?
D: The function definition must be written in the class.
The advantage of the function is that it avoids duplication of code and makes the code easier to read.
function declaration? When the arguments are called parameters, the parameters of the function call are called arguments, and the values of the arguments are passed to the arguments, parameters, and variables in the body of the function, and are cleared after the call is complete.
public static void Main (string[] args) {
int a=2;
Method (a);
System.out.println (a);
}
public static void Method (int a) {
A=3;
}
The output result is 2.
return type + function name + parameter = function signature
A good function name implies a return type and a parameter list, and if not, use the document comment (?).
The principle of function partitioning: dividing repetitive or complex functions into functions.
Java Fundamentals 06