Java implementation comparing two values of the array

Array size comparison rules:

According to the string comparison rules:

1. The two arrays are equal in length: sequentially comparing array elements, determines a large element of the large array;

2. The two arrays unequal length: sequentially comparing array elements, determines the large array of large elements, if a small length of all elements of the array and comparing the array length End length equal to the number of groups is determined that a large number of head;

public static int[] large(int[] a,int[] b){

if (a.length==0&&b.length!=0)

return b;

if(b.length==0&&a.length!=0)

return a;

if(a.length!=0&&b.length!=0){

   int m=a.length;

   int n=b.length;

   int k=(m>n)? m:n;

   for(int i=0;i<k;i++){

       if(a[i]>b[i]){

          retunrn a;

           }else

            if(a[i]<b[i]){

            return b;

            }else if(a[i]==b[i]){

               i++;

             }

       }

   }

}

Guess you like

Origin www.cnblogs.com/pcy226/p/11526411.html