1. Better application of three cycle structures:
1) while: "When ..." loop
2) Do...while: "Until ..." loop
Preferred Do...while when feature 1 is the same as feature 3
3) for: fixed number of cycles
2. Nested loops:
1) loop in the loop, generally multi-row multi-column when used, the outer control row, Memory control column
2) Execution rules: Outer loop Walk once, inner layer cycle all times
3) Recommendation: The fewer layers of nesting, the better, can use a layer of two layers, can use two layers without three layers
If the demand must pass through three layers of cycle can be solved, indicating that the design of a problem
4) Break can only jump out of a layer of loops
3. program = algorithm + data structure
1) algorithm: process/step for problem Solving (order, branch, Loop)
2) Data structure: to save it in a specific structure
Number How to save
Well-designed/reasonable data structures can lead to good algorithms
4. Arrays:
1) Collection of elements of the same data type
2) An array is a data type (reference type)
3) Declaration of the array:
int[] arr = new INT[10];
4) Initialization of the array:
int[] arr = new INT[3]; 0,0,0
Int[] arr = {1,4,7}; 1,4,7
int[] arr = new int[]{1,4,7}; 1,4,7
Int[] arr;
arr = {1,4,7}; Compile error, this method can only be declared at the same time initialization
arr = new int[]{1,4,7}; That's right
5) Array of access:
5.1) You can get the length of the array by (array name. length)
int[] arr = new INT[4];
System.out.println (arr.length); 4
5.2) access to elements in the array by subscript/index
Subscript starting from 0, Max to (length of array-1)
int[] arr = new INT[3];
ARR[0] = 100;
ARR[1] = 200;
ARR[2] = 300;
ARR[3] = 400; Array subscript out of bounds exception
System.out.println (Arr[arr.length-1]); Output last Element
6) Array Traversal:
int[] arr = new INT[10];
for (int i=0;i<arr.length;i++) {
Arr[i] = 100;
}
for (int i=0;i<arr.length;i++) {
System.out.println (Arr[i]);
}
for (int i=arr.length-1;i>=0;i--) {
System.out.println (Arr[i]);
}
7) Copying of arrays:
7.1) system.arraycopy (a,1,a1,0,4);
7.2) int[] A1 = arrays.copyof (a,6);
A = arrays.copyof (a,a.length+1); Expansion
8) sort the array:
8.1) Arrays.sort (arr); Ascending, high efficiency
8.2) Bubbling principle:
8.2.1) Four count three rounds
8.2.2) Each round starts with a 1th element
Every time it's the next element.
8.2.3) is out of the execution.
I am a beginner, if the update is not good, welcome the Great God pointed out, thank you!
More exciting after the update, reprinted annotated!
Application environment for java-loops and creation of arrays