随便写个public class test {
public static void main(String args[]) {
int a[] = {1,4,31,41,51};
int b[] = {11,22,32,42,52,54};
int c[] = sort(a,b);
for(int n=0; n<c.length; n++)
System.out.println(c[n]);
} private static int[] sort(int[] a, int[] b) {
int c[] = new int[a.length+b.length];
int n = 0;
int i = 0;
int j = 0;
while(i<a.length&&j<b.length) {
if(a[i]<b[j]) {
c[n] = a[i];
n++;
i++;
}else {
c[n] = b[j];
n++;
j++;
}
}
while(i<a.length) {
c[n] = a[i];
n++;
i++;
}

while(j<b.length) {
c[n] = b[j];
n++;
j++;
}
return c;
}
}

解决方案 »

  1.   

    public class test {
        public static void main(String args[]) {
             int a[] = {3,43,6,41,53};
            int b[] = {2,12,32,42,152,54,9};
            int res[] = new int[a.length+b.length];
    System.arraycopy(a,0,res,0,a.length); 
    System.arraycopy(b,0,res,a.length,b.length); 
    sort(res);
        }
       
        public static int[] sort(int[] b){
      int a[] = b;
       for(int i=1;i<a.length;i++){
       for(int j=0;j<a.length-i;j++){
       if(a[j]>a[j+1]){
       int temp = a[j];
       a[j] = a[j+1];
       a[j+1] = temp;
       }
       }
       System.out.print("第"+i+"次循环结果:");
       for(int k=0;k<a.length;k++){
       System.out.print(a[k]+" ");
       }
       System.out.println("");
       }
       return a;
       
      }
    }
      

  2.   


    public class Test3 {
        public static void main(String args[]) {
            int a[] = {1,4,31,41,51};
            int b[] = {11,22,32,42,52,54};
            int c[] = sort(a,b);
            for(int n=0; n<c.length; n++)
                System.out.println(c[n]);
        }    public static int[] sort(int[] a,int[] b){
         int[] c=new int[a.length+b.length];
         System.arraycopy(a, 0, c, 0, a.length);
         System.arraycopy(b, 0, c, a.length, b.length);
         for(int i=0;i<c.length;i++){
         for(int j=0;j<c.length-i-1;j++){
         int x=c[i];
         int y=c[i+1];
         if(x>y){
         c[i+1]=x;
         c[i]=y;
         }
         }
         }
         return c;
        }
    }