definition, declaration and ordering of one-dimensional Java arrays

Source: Internet
Author: User

 Public classTestarray { Public Static voidMain (string[] args) {/**Array declaration and dynamic initialization int a[] = new Int[args.length];        for (int i=0;i<args.length;i++) {A[i] = Integer.parseint (Args[i]); }         **/        //Static Initialization        intA[] = {9,8,1,3,7,5,4,2,6};        Print (a);        Bubblesort (a);    Print (a); }    /**     * @paramA input parameter is an array * next to the output array contents*/    Private Static voidPrintinta[]) {         for(inti=0;i<a.length;i++) {System.out.print (A[i]+ " ");    } System.out.println (); }    /**     * @paramA enter parameter is an array * Select Sort method*/    Private Static voidSelectionsort (inta[]) {        intk,temp;  for(inti=0;i<a.length;i++) {k=i;  for(intj=k+1;j<a.length;j++) {                if(A[k] >A[j]) {k=J; }            }            if(k! =i) {temp=A[k]; A[K]=A[i]; A[i]=temp; }        }    }    /**     * @paramA Enter parameter is an array * bubble Sort method*/    Private Static voidBubblesort (inta[]) {        inttemp;  for(inti = a.length-1;i>=1;i--){             for(intj=0;j<=i-1;j++) {                if(A[j] > a[j+1]) {temp= A[j+1]; A[j+1] =A[j]; A[J]=temp; }            }        }    }}

definition, declaration and ordering of one-dimensional Java arrays

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.