1. function 1) Definition: defines an independent applet with specific functions in the class; 2) Format: modifier Return Value Type Function Name (parameter Type format parameter 1, parameter Type format parameter 2) {execution statement; return value;} 3) features ** feature code can be encapsulated; ** this feature is easy to reuse; ** a function is executed only when it is called. ** the appearance of a function improves code reusability. ** if a function does not return a specific value, the return value type is represented by the keyword void, the return statement in this function can be omitted without writing. If it is written, it is return; 2. function overload features: it has nothing to do with the return value type. It only looks at the parameter list, that is, the number of parameters and parameter type. advantages: it is easy to read and optimizes the program design. 3. array definition: a collection of the same type of data. In fact, an array is a container. Its advantage is that it can be numbered from 0 to facilitate operations on these elements. An array is a variable that stores a group of data of the same type; the array is created in the memory. If we do not assign a value to it, the system will assign a value to it by default. Static array initialization: int [] arr = {1, 2, 4}; array dynamic initialization: int [] arr = new int [5];
4. memory Structure Analysis stack memory: used to store local variables. when data is used up, the occupied space is automatically released. heap memory: 1) arrays and objects are stored in the memory through the new object; 2) each object has a memory address value. 3) all variables in the object have default initialization values. 4) the object is no longer used and will be recycled by the garbage collector in an uncertain time! 5 select sorting for (INT x = 0; x <arr. length-1; X ++) {for (INT y = x + 1; y <arr. length; y ++) {int temp = arr [X]; arr [x]> arr [y]; arr [y] = temp ;}} 6. bubble Sorting light floating, heavy sinking for (INT x = 0; x <arr. length; X ++) {for (INT y = 0; y <arr. length-1-x; y ++) {//-1 prevents array subscripts from crossing the border-x improves efficiency if (ARR [y]> arr [Y + 1]) {int temp = arr [y]; arr [y] = arr [Y + 1]; arr [Y + 1] = temp ;}} arrays are used in actual development. tostring (ARR); statement to print the array arrays. sort (ARR); used to sort arrays 7. binary Search --- ordered array idea: the minimum badge is 0, and the maximum badge is arr. length-1 calculates the average value of the lower mark, and then compares the key to be searched with arr [Mid]. If key> arr [Mid], min = Mid + 1; re-calculate the mid value and then compare it. If the key <arr [Mid], max = mid-1, re-calculate the mid value and then compare it.
Public int halfsearch (INT [] arr, int key) {int min = 0; int max = arr. length-1; while (Min <= max) {int mid = (min + max) >>> 1; if (Key> arr [Mid]) {min = Mid + 1;} else if (Key <arr [Mid]) {max = mid-1;} else {return mid ;}} return-1 ;}
8. array inversion algorithm 1: Public static void revarray (INT [] ARR) {for (INT start = 0, end = arr. length-1; Start <end; Start ++, end --) {int temp = arr [start]; arr [start] = arr [end]; arr [end] = temp;} algorithm 2: public static void revarray (INT [] ARR) {for (INT I = 0; I <arr. length/2; I ++) {int temp = arr [I]; arr [I] = arr [arr. length-1-I]; arr [arr. length-i-1] = temp;} 9. convert decimal to hexadecimal char [] CH = {'0', '1', '2', '3', '4', '5 ', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E ', 'F'}; char [] arr = new char [8]; Public void tohex (INT num) {int x = arr. length-1; while (Num> 0) {int temp = num & 15; arr [x] = CH [temp]; X --; num = num >>> 4 ;} for (INT I = x + 1; I <arr. length; I ++) {system. out. print (ARR [I]) ;}} 10. two-dimensional array format 1: int [] [] arr = new int [2] [3]; defines a two-dimensional array named arr, A two-dimensional array has two one-dimensional arrays, and each one-dimensional array has three elements. The names of one-dimensional arrays are: arr [0], arr [1] Format 2: int [] [] arr = new int [3] []; If: system. out. println (ARR [0]); the result is null. There are three one-dimensional arrays in the two-dimensional array. The default initialization value of each one-dimensional array is null. You can initialize these three arrays separately: arr [0] = new int [5]; arr [1] = new int [3]; arr [2] = new int [2]; format 3: int [] [] = {, 3}, {}, {9, 0,}; For (INT x = 0; x <arr. length; X ++) {// traverse each array for (INT y = 0; y <arr [X]. length; y ++) {// traverse each array element system. out .. println (ARR [x] [Y]) ;}}: int [] Y, X []; // This statement indicates that Y is a one-dimensional array and X is a two-dimensional array; 1) x = y; // Error 2) x [0] = y; // correct 3) x [0] = Y [0]; // error 4) X = Y [0]; // error 5) x [0] [0] = Y [0]; // correct