//倒置
public class Arriy { public static void main(String args[]){ int data[]=new int[]{10,78,24,33,87,5,44,9,55}; arrayinc(data); printarray(data); } public static void arrayinc(int array[]){ int head=0; int tail=array.length-1; int center=array.length/2; for(int x=0;x<center;x++){ int temp=array[head]; array[head]=array[tail]; array[tail]=temp; head++; tail--; } } public static void printarray(int arr[]){ for(int x=0;x<arr.length;x++){ System.out.print(arr[x]+"、"); } } }
//冒泡
public class Arriy { public static void main(String args[]){ int data[]=new int[]{10,78,24,33,87,5,44,9,55}; arrayinc(data); arr(data); } public static void arrayinc(int array[]){ for (int x=0;x<array.length-1;x++){ for(int y=0;y<array.length-1;y++){ if(array[y]>array[y+1]){ int temp =array[y]; array[y]=array[y+1]; array[y+1]=temp; } } } } public static void arr(int temp[]){ for(int x=0;x<temp.length;x++){ System.out.print(temp[x]+"、"); } } }