2. Control statements and Arrays

Source: Internet
Author: User
Tags case statement switch case

1. Three types of control structures

Sequential selection Loops

2.math.random () is a pseudo-random double value that is randomly selected for a system that is greater than or equal to 0.0 and less than 1.0

The result value of an expression in 3.switch must be an integer, a character, or an enumeration measure

4.switch Case statement: executes sequentially from match until a break or end is encountered

5.switch statement, default can not write

6. Cyclic structure simulation realizes formal logic in the real world, dialectical logics and causal logic

7. Four internal structures of the loop structure for the foreach while Do While

8.while is the first to judge the execution, do while is the first to perform the re-judgment

The difference between 9.break and continue

Break: Ignores statements after the statement, jumps out of the loop body, executes the statement below the loop body

Continue: Ignores statements after the statement, performing the next loop of the loop body

10.return is used when defining a method; return is the function of returning the result of the execution of the method, what value is returned on success, what value is returned when it fails, and return value type can be customized

11. Passing by value and by reference

In Java, parameters are passed by value, and are worth copying, and are not correlated after delivery.

int a=3;

T.test (a);

In Java, by reference, passing is the address of the reference, that is, the address of the memory space corresponding to the variable (both before and after the pass point to the same reference, that is, the same memory space)

A a=new a ();

T.test (a);

12. Formal parameters and arguments

Defines the function void add (int a,int b) Here, A, a, is the formal parameter (used when defined)

The function calls add, which is the actual argument (used when invoked)

Parameter parameters are variables that are not assigned (you do not necessarily write variable types when defining formal parameters)

The actual argument is a variable that has a value assigned to it

13. Method overloading refers to a class where multiple methods with the same name are defined, but each method is required to have a different parameter type or number of arguments, and the return value can be the same (therefore, the return value cannot be used to differentiate the method overload)

14. Advantages and disadvantages of recursion

Pros: The code is more concise and clear, more readable

Cons: Because recursion requires a system stack, space consumption is much larger than non-recursive code

The array element type of the 15.java language must be specified at compile time, the array size can be specified at run time, but cannot be changed once specified

16. An array is a reference type and an object, the type of an array can be any type, and the Subscript (index) of an array is [0,n-1]

17. The elements in the array are the same as the member variables in the object, as are the initialization methods

18. Three types of initialization in the array:

1. Default initialization: int[] a=new int[10];

2. Static initialization: int[] a={1,2,3}

3.FOR Cyclic dynamic initialization

19. The correct definition of a two-D array:

int a[][]=new int[3][3];

Int[][] A=new int[3][3];

Int[][] A=new int[2][];

20. Variable parameters (java1.5 new features)

For cases where the parameter number is indeterminate and the type is determined, Java treats the mutable parameter as an array

Characteristics:

---can only appear at the end of the argument list

---is between the variable type and the variable name, there are no spaces before and after it can

---a method that calls a mutable parameter, the compiler creates an array for the mutable parameter implicitly, accessing the mutable parameter as an array in the method

The 21.main method is the portal to the Java Program application, and the arguments passed to main can only be string strings, and there are two ways to pass the arguments: (1) from command-line arguments (2) with IDE development tools

2. Control statements and Arrays

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.