The loop structure and array of Java basics

Source: Internet
Author: User
Tags array length

1.for Loop: For (initialization of the loop variable 1; loop condition 2; Change of loop variable 3) {
Circulation Body 4;
}
The order of execution is: 1,2,4,3,2,4,3,2,4,3,2,4,3 ..... End loop when 2 is False
2.break: Jump out of this layer loop, continue skip this cycle, do not execute the following statement directly to the next loop.
3. Use of three cycles:
1. Feature 1 differs from feature 3, preferred while
2. Feature 1 is the same as feature 3 when Do...while is preferred
3. Number of fixed cycles preferred for
4. Loop nesting:
1. Loop in the loop, the general multi-line queue use, the outer control row, the inner control column.
2. Execution rules: Outer walk once, inner layer cycle all the time,
3. It is suggested that the less nested loops, the better, can use a layer of 2 layers, can use two layers without three layers.
4.break can only jump out of a layer of loops
5. Program = data structure + algorithm
Data structure: How to store and manipulate
Algorithm: Steps/processes to solve the problem (order, branch, Loop)
A well-designed and reasonable data structure can lead to good algorithms
-----------first design the data structure, and then the algorithm.
6. Arrays
1. Is a data type, reference type
2. Collections of the same data type
3. Definition of the array:
int [] A = new int [10];
4. Initialization of the array:
int [] A = {n/a};
int [] A = new int[]{1,2,3};
5. Access to arrays:
1. The array length can be obtained by using the array name. length
2. Use subscript to access array elements, subscript starting from 0, Max to Length-1
6. Traversal of the array:
int [] a =new int[10];
for (int i =0;i<a.length;i++) {//traversal array
a[i]=i;//Array Assignment
}

Loop structure and array of Java basics

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.