Exercise 13 (one array)

Source: Internet
Author: User

A bunch of people
PackageCN.CH.W; Public classPersonarray { Public Static voidMain (String args[]) {person per[]=NewPerson[3]; per[0]=NewPerson ("straw mushroom", 20); per[1]=NewPerson ("mushroom", 22); per[2]=NewPerson ("Pleurotus ostreatus", 23); for(intx=0;x<per.length;x++) {per[x].getinfo (); } }}
 PackageCN.CH.W; Public classPerson {PrivateString name; Private intAge ;  PublicPerson (String name,intAge ) {         This. name=name;  This. age=Age ; }     Public voidGetInfo () {System.out.println ("Name:" + This. name+ "Age:" + This. Age); }}

One array

 PackageCN.CH.W; Public classA { Public voidGetfibonacci (intNumber ) {        intNleft = 0; intNright = 1;        System.out.print (Nright);  for(inti = 0; I < number; i++) {        intsum = Nleft +Nright; System.out.print (" " +sum); Nleft=Nright; Nright=sum; }        }         Public Static voidMain (string[] args) {NewA (). Getfibonacci (10); }}

Selection method

 PackageCN.CH.W; Public classA { Public Static voidMain (string[] args) {int[] arr={23,234,3,1,19,21,231,88,90,11};  for(inti=0;i<arr.length-1;i++) {             for(intj=i+1;j<10;j++) {                if(arr[i]>Arr[j]) {                    inttemp; Temp=Arr[i]; Arr[i]=Arr[j]; ARR[J]=temp; }            }        }          for(inti=0;i<arr.length;i++) {System.out.println (arr[i]); }     }}

Bubble

 PackageCN.CH.W; Public classA { Public Static intMain (string[] args) {int[] arr={23,234,3,1,19,21,231,88,90,11};  for(inti=0;i<10;i++) {             for(intj=0;j<10-1-i;j++) {                if(arr[j]>arr[j+1]) {                    inttemp; Temp=Arr[j]; ARR[J]=arr[j+1]; Arr[j+1]=temp; }            }        }         for(inti=0;i<arr.length;i++) {System.out.println (arr[i]); }        return0; }}

Exercise 13 (one array)

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.