It 18 palm Big data third day the meaning function of the 1.&NBSP;1 function is defined as a separate applet in the class that has a specific function. The function is also called a method. 1.2 function format modifier return value type function name (parameter type formal parameter 1, parameter type form Parameter 2, ...) { EXECUTE statement; return return value; } the data type of the return value is the parameter that is determined by the result of the function's run: is a variable that stores the actual arguments passed to the function when the function is called actual parameters: Specific values passed to formal parameters return: Used to end functions return values : The result of the function's operation, which is returned to the caller. ** for cases where the function does not have a specific return value, the return value type uses the keyword void to denote, if the return statement in the function can be omitted from the last line if not written. Note that only functions can be called in the: function, and functions cannot be defined inside the function. when a function is defined, the result of the function should be returned to the caller, which is handled by the caller. The function needs to be clear when applying the function of define what the final result is whether unknown content is required to participate in the operation during the process of defining the function explicitly defines a function that implements two integers added class FunctionTest { public static Void main (String [] args) { system.out.println (Sum (2,3)); } public static Int sum (int a , int b) { return a+b; }} This function can implement overloading of call functions on sum in the same class, allow more than one function of the same name, as long as their number of arguments or different types of parameters feature: is independent of the return value, see only the parameter list class functiontest { public static void main ( String [] args) { system.out.println (Sum (2,3)); System.out.println (Sum (2,3,4)); } public static int sum (int a , INT&NBSP;B) { //defines two parameters return a+b; } public Static int sum (int a, int b, int c) { //defines three parameters that can be return a+b+c; &nbSP;}} Array array----------------concept : A collection of data of the same type. (An array is a container) benefit: can automatically number the elements in the array, starting with 0, to conveniently manipulate these elements. Format: format 1 element type [] array name = new element type [element number or array length] example: int [] arr =new int [6] //represents the length of the , element of the element int is 6 (Result is 7 elements since 0) format 2 element type [] array name = new [] { element, element ...}; Example: int [] arr =new int []{1,2,3}; int [] Arr= {3,5,7,9};class arraydemo {public static void main (String[] args) {int[] arr=new int [6];int[] arr2=new int[]{1,2,3};int [] arr3= {3,5,7,9}; System.out.println (arr.length); // print array length arr.length is the default property System.out.println (arr2.length); System.out.println (arr3.length); }} array in memory form arrays are contiguous in memory the following table starts with 0 //access to a number in an array you can use ARR (subscript to implement such as [1,2,3,4] arr[0] that represents the first number of the array 1. //the length of the array is The maximum value in the arr[length] array is the number of arr[length-1] in the array without arr[length], If the interview will be error //arraindexoutofboundexception : Array out of bounds exception int[] arr=new int [6]; a total of three steps 1-defines an array of type int 2-Creates a space in memory 3-associates the two together Heap:heap --------------- object heap //arrays are located in heap // new instances are in heap memory //because all objects are in the heap area, if the heap settings are too small, the object will be stacked overflow (usually stack overflow) heap overflow heap overflow stack overflow stack Overflow stack stack ----------------  The; method stack method stack corresponds to at least one thread (the thread where the main course main function is located) each method in the stack is called a method frame method frame push stack : stack pop stack : Stack java no pointer refers to an explicit pointer operation. The reference is the pointer (the name of the variable) NullPointerException is a null pointer exception (runtimeexception)//arr []=null; is run-time exception practice; takes the maximum value in the array and encapsulates the class ArrayMax{ The name of the //class must be the same as the name of the file after it is compiled, otherwise the run will error. Public static void main (String[] args) { system.out.println ( Getmax (new int []{2,5,21,5,7}));} public static int getMax (Int [] arr) { //from robustness considerations should take into account the arr== The null and arr.length lengths are 0. if (arr == null| | arr.length==0) { //Short circuit andFirst judge the big system.out.println ("array does not exist"); return -1; //when in both cases, the error is prompted and a result of 1 is returned. } int temp =integer.min_value; //integer.min_value is the minimum value of the integer number for (int i=0; i < arr.length ; i++ ) {if (Temp < arr[i]) { temp = arr[i] ; }} return temp; } } If the minimum value in the array is evaluated , it is necessary to replace the Temp =integer.min_malue with---> temp =integer.max.malue, temp<arr (i)-->temp >arr (i) to sort the array (from small to large) thoughts iterated algebraic group elements--Find the corner mark corresponding to the minimum and minimum values--displacement position--return array--encapsulation--Call class arrayselectsort{public static void main (String[] args) {outArr (sort (new int []{2,1,6,4,9}); //call Array} public static int[] sort (Int[] arr ) {&NBSP;&NBSP;&NBSP;&NBsp; if (arr == null| | arr.length == 0) { // Exclusion of null and length of 0 system.out.println ("Array does not exist"); } // Determine the minimum value of the number in the next digit for (int i =0;i < arr.length ;i++ ) { // Iterate through all the numbers in the array int aa=Integer.MAX_VALUE; int index = 0 ; //the initial variable that defines the angle label is 0 for (int j= i + 1;j < arr.length;j++ ) {//all numbers following the arr[i] number, to find the minimum value if ( aa > arr [j]) {&NBSP;&NBSP;AA = arr [j]; //assigns a small value to temp index = j ; // Gets the small value of the corner label// system.out.println (AA) ; } } // Select the smaller of the numbers in the backValue, if it is smaller than itself, swap position if (ARR[I]>AA) { arr[index] = arr[i]; // Arr[i] This larger value is assigned to Arr[index], where arr[index] acts as an intermediate amount, at which time arr[] is empty arr[i] =aa ; //then aa Assigning a value to a arr[i] that is already a null value implements the interchange position of the two numbers. } } return arr; //return arr Array } public static void outArr (Int [] arr) { //Package outarr method for (int i = 0; i < arr.length ;i++ ) { system.out.print (arr[i]+ " "); //Print arr[i] this array } }} question: ****************************** Why when int aa=Integer.MAX_VALUE; in: int index = 0 ; in: for (int i =0;i < arr.length ;i++ ) { //The result of printing is incorrect when traversing all the numbers in the array. Bubble Sort * * * bubble sort, the value will be automatically compared with the next one * * * * SO 5,4,3,2,1 If the bubble sort, only need to fetch &NBSP;ARR[3] ,arr[3] will be automatically compared with arr[4]. So you don't need to take arr[4] Example: Use a large number of sinks bubble sort Class bubblesort{public static void main (String [] args) {outarr (Bubble (new int[]{ 3,6,8,2,1,5,9}));} public static int[] bubble (Int [] arr) { //definition function Array //large number of sinking way for (int i = 0;i < arr.length - 1 ;i++ ) { //Outer loop count for arr.length-1 for (int j = 0;j < arr.length - 1 - i ;j++ ) { //n Inner Loop frequency is arr.length-1-i int temp= 0; //defines a temporary variable is used to receive data //the data is swapped (because it is a large number sinking way) if ( Arr[j]>arr[j+1]) { temp = arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp;} }} return arr; //returns the array } public static void outarr (Int [] arr) { //encapsulation method for (int i=0 ;i< Arr.length&nbSP;; i++ ) { system.out.print (arr[i]+ " "); } }}*************** for (int j = 0;j < arr.length - 2 - i ;j++ ) { //n inner loop count is arr.length-1-i why-2 and -1 results same *************** binary lookup if the search results are 10 1,3 ,5 ,7,8,10,11 binary The first binary words are 7, the second binary is 10 (second time from 8) binary find data to order Find the first occurrence of 6 in 1-9 numbers. class halffind{public static void main (String[] args) { System.out.println (Find (new int []{1,2,3,4,5,6,7,8,9},6));} public static int find (int [] arr,int n) { //definition function * definition A int type of digital int a = 0 ;int b = arr.length ; int m = 0 ; //define three variables "A&nbsP;b "Corner Mark m (for median value) int mindex = 0; //Intermediate angle Mark //defining Loops while (A&NBSP;<=&NBSP;B) { //Cycle conditions mindex = (a + b) /2 ; //calculate the midpoint of the intermediate volume m = arr[mindex]; //calculate the value of M //Judge M and if ( m == n ) { //if m and query values are equal note is "= =" return mindex; } //query range falls on the left else if (m > n) { b= mindex - 1; } //query range falls to the right else { a = mindex + 1; } } return - 1 ; //return value &nbSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP: Array of arrays--------------------- Two-dimensional array format 1: int [][] arr = The new int [3][4]; //represents a two-dimensional array named arr, with 3 two-dimensional arrays, 4 elements per group the names of each array are arr[0],arr[1];arr[2]; If you assign a value of to the first array with a corner mark of 1, the notation is arr[0][1]= x; format 2; int[][] arr= new int[2][]; 2 One-dimensional arrays in two-dimensional arrays each one-dimensional array is the default initialization value null can initialize this two one-dimensional array individually arr[0] = new int[3]; //the first array of has 3 elements. arr[1] = new int[1]; // the second array of has 1 elements. Print inverted two-dimensional array class multiarray {public static void main (String[] args) { int [][] arr= new int[4][3]; //defines a two-dimensional array arr[4][3]int a= 12; // Defines a number starting from 12 for (int i = 0;i<arr.length ;i++ ) { //defines the outer function (with several two-dimensional arrays) for (int j = 0;j<3 ;j++ ) { //defines the inner layer function (how many elements are in each array) arr [i][j] = a; //assignment of a--; //to the first J element of line I 1 }}outarr (arr); //call}public static void outarr (int [][] arr) { //definition outarr function for (int i = 0;i <arr.length ;i++ ) { for (int j=0 ;j< 3 ;j++ ) { system.out.print (arr[i][j]+ "\ T"), //print Arr[i][j] Value } system.out.println (); }}}/*123 [0][0] [0][1] [0][2] 456 [1][0] [1][1] [1][2] 789 [2][0] [2][1] [2][2] 101112 [3][0] [3][1] [3][2]121110 [3][2] [3][1] [3][0] [i][j] arr.length-1-i987 [2][2] [2][1] [2][0] &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;A--654&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;[1][2]&NBSP;&NBSP;[1][1] [1][0]321 [0][2] [0][1] [0][0 ]*/
It 18 Palm Third day Course summary