Java Learning Note day02

Source: Internet
Author: User

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

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.