The java=== array tool class is created, and the description document is exported using Eclipse. html

Source: Internet
Author: User
Tags array sort

 PackageCn.china;//import java.util.Arrays;//import Java.util.Scanner;/*** Array Tool class, and the class internal methods are static methods, do not provide initialization object calls!!! * Includes array sorting, maximum value, find and more methods *@authorWang Daxia *@versionV1.0*/ Public classArraytool {PrivateArraytool () {}/*** Array selection sort *@paramarr passes an array to validate the program*/     Public Static voidArraySort (int[]arr] {         for(intx=0;x<arr.length-1;x++){             for(inty=x+1;y<arr.length;y++) {Exchange (arr, x, y); }        }    }    Private Static voidExchangeint[]arr,intXinty) {        if(arr[x]>Arr[y]) {            inttemp=Arr[x]; ARR[X]=Arr[y]; Arr[y]=temp; }    }    /*** Bubble Array Sort *@paramarr passes an array for validator * Incoming Array validator*/     Public Static voidArraysort2 (int[]arr] {         for(intx=0;x<arr.length-1;x++){             for(inty=0;y<arr.length-1-x;y++) {Exchange (arr, y, y+1); }        }    }    /*** Array Maximum value extraction *@paramarr passes an array to validate the program *@returnMax Returns the maximum value*/     Public Static intArraymaxint[]arr] {        intMax=arr[0];  for(intx=0;x<arr.length;x++){            if(max<Arr[x]) {Max=Arr[x]; }        }        returnMax; }    /**array Minimum value extraction@paramarr passes an array to validate the program@returnreturns the minimum value*/     Public Static intArraymin (int[]arr] {        intMin=arr[0];  for(intx=0;x<arr.length;x++){            if(min<Arr[x]) {min=Arr[x]; }        }        returnmin; }    /*** Find array elements *@paramarr passes an array to validate the program *@paramkey to pass in a data to find *@returnx Returns the look-up data in the array with the corner label *@return-1 data not found return-1*/       Public Static intArraysearch (int[]arr,intkey) {         for(intx=0;x<arr.length;x++){            if(arr[x]==key) {System.out.println ("Find data in an array with a corner labeled as:"); returnx; }} System.out.println ("No related element found in array"); return-1; }//Public void Arraysdelete () {//Scanner SC =new Scanner (system.in);//int[] arr = new int[]{1,2,4,5,9,8,0};//System.out.println (arrays.tostring (arr));//System.out.println ("Please enter the number of elements to delete:");//int n = sc.nextint (); Sc.close ();//arr[n-1] = arr[arr.length-1];//arr = arrays.copyof (arr, arr.length-1);//System.out.println (arrays.tostring (arr));////        }     /*** Array Inversion *@paramarr passes an array to validate the program*/     Public Static voidInvertarray (int[]arr] {        intHead=0; intTail=arr.length-1; intMid=arr.length>>1;  for(intx=0;x<mid;x++){            inttemp=Arr[head]; Arr[head]=Arr[tail]; Arr[tail]=temp; Head++; Tail--; }    }    /*** Print Array *@paramarr passes an array to validate the program*/     Public Static voidPrintarr (int[]arr] {System.out.print ("[");  for(intx=0;x<arr.length;x++){            if(x==arr.length-1) {System.out.print (arr[x]+"]"); }Else{System.out.print (arr[x]+","); }        }    }    /*** Print two-dimensional arrays and calculate the sum of the data within the two-dimensional array *@paramarr passes an array to validate the program *@returnSums returns the sum of two-dimensional array elements*/     Public Static intAddArray (int[][]arr] {        intSum=0;  for(intx=0;x<arr.length;x++){             for(inty=0;y<arr[x].length;y++){                //System.out.print (arr[x][y]+ ",");sum+=Arr[x][y]; }        }        returnsum; }    /*** Binary search * Precondition incoming array must be ordered *@paramarr passes an ordered array for validator *@paramkey incoming to search for data *@returnMid Returns the corner label of the search data in the array *@returnNo search data is found in the array, returns the inverse value of the insertion position of this data in this array*/      Public Static intBinarySearch (int[]arr,intkey) {          intMin=0; intMax=arr.length-1; intmid;  while(min<=max) {Mid= (Min+max) >>1; if(arr[mid]<key) {min=mid+1; }Else if(arr[mid]>key) {Max=mid-1; }Else{                    returnmid; }            }            return~min; }}
 PackageCn.china; Public classTestdriver { Public Static voidMain (string[] args) {//int[]arr={1,2,5,6,34,87,505};        int[][]arr={{11,2,5},{62,34},{871,50}}; //int Max=arraytool.arraymax (arr);                intA=Arraytool.addarray (arr);        System.out.println (a); //Arraytool.printarr (arr);    }}

export==java==javadoc==next== Add Javadoc path ==finish document format can be created successfully without error!!!

The java=== array tool class is created, and the description document is exported using Eclipse. html

Related Article

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.