Java Fundamentals 06

Source: Internet
Author: User

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

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.