1. How do you define a function and show it through a function (method)?
1) Clear the result after the function operation is changed. Determines the return value type of the function.
2) Determine whether there is unknown content involved in the operation in the implementation of this function. Determine the parameter list.
2. Function overloading: In the same class, it is permissible to have more than one function of the same name, as long as the number of arguments or the type of parameter is different, overloading the function.
Overloads do not have a relationship with the return type of a function
3. Array sorting:
1)/*Select the sorting feature: at the first end of the inner loop, the minimum angular mark appears*/ Public Static int[] Sort (int[] arr) { inttemp; //System.out.println (arr.length); for(intx=0;x<=arr.length;x++){ for(inty=x+1;y<arr.length;y++){ if(arr[x]>Arr[y]) {Temp=Arr[x]; ARR[X]=Arr[y]; Arr[y]=temp; } } } returnarr; } 2) Bubble Sort/*Bubble sort feature: Adjacent two table elements are compared within the loop end once and the maximum value appears in the last corner of the label. */ Public Static voidBubblesort (int[] arr) { inttemp; for(intx=0;x<arr.length-1; x + +){ for(inty=0;y<arr.length-x-1;y++){ if(arr[y]>arr[y+1]) {temp=Arr[y]; Arr[y]= Arr[y+1]; Arr[y+1] =temp; } } } } 3) array for maximum value (max and Min) A. Maximum/*find the maximum values in the array: 1. Define a variable to record the value after each comparison larger in that value. 2. How does this variable initialize? Initialized to any one of the elements in the array. 3. Continue to compare the elements in the array with the variable through the loop. 4. If the element that appears is larger than the variable, the value is recorded with the variable. */ Public Static intMaxValue (int[] arr) { intmax = Arr[0]; for(intx=1;x<arr.length-1;x++){ if(arr[x]>max) {Max=Arr[x]; } } returnMax; } b. Minimum value Public Static intMinValue (int[] arr) { intMin = 0; for(intx=1;x<arr.length;x++){ if(arr[x]<Arr[min]) {min=x; } } returnArr[min]; }
Java Learning Note day02