Advertisement
Khoa98

câu 4

Feb 15th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. public static String [] KetHop(String A[], String B[]) {
  2.         int cLength = A.length + B.length - 1;
  3.         String C[] = new String[cLength + 1];
  4.  
  5.         int i = 0, j = 0, n = 0;
  6.         if (A.length > B.length) {
  7.             n = B.length;
  8.         } else {
  9.             n = A.length;
  10.         }
  11.         while (i <= cLength) {
  12.             if (j < n) {
  13.                 C[i] = A[j];
  14.                 C[i + 1] = B[j];
  15.                 i += 2;
  16.             } else {
  17.                 if (n == A.length) {
  18.                     C[i] = B[j];
  19.                 } else {
  20.                     C[i] = A[j];
  21.                 }
  22.                 i += 1;
  23.             }
  24.             j += 1;
  25.         }      
  26.         return C;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement