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)