Respuesta :
Answer:
import java.util.*;
import java.io.*;
class Merge
{
 public static void main (String[] args) throws FileNotFoundException
 {
   File file1 = new File(args[0]);
   File file2 = new File(args[1]);
  Â
   Scanner in;
  Â
   in = new Scanner(file1);
  Â
   int i, p, q;
  Â
   int a[] = new int[100];
   int b[] = new int[100];
   int c[] = new int[100];
  Â
   i = 0;
   while(in.hasNextInt())
   {
     a[i] = in.nextInt();
     i++
   }
   int n = i;
  Â
   i = 1;
   while( i < n )
   {
     int t = a[i];
     for(p=i-1; p>=0 && t<a[p] ; p--)
       a[p+1] = a[p];
     a[p+1] = t;
     i++;
   }
  Â
   in = new Scanner(file2);
Â
   i=0;
   while(in.hasNextInt())
   {
     b[i] = in.nextInt();
     i++;
   }
   int m = i;
  Â
   for(i=1; i<m; i++)
   {
     int t = b[i];
     for(p=i-1; p>=0 && t>b[p] ; p--)
       b[p+1] = b[p];
     b[p+1] = t;
   }
  Â
   i=n-1; p=0; q=0;
  Â
   do
   {
     if(a[i]>b[p])
       c[q++] = a[i--];
     else
       c[q++] = b[p++];
   } while(i>=0 && p<m);
  Â
   do
   {
     c[q++] = a[i--];
   } while(i>=0)
  Â
   do
   {
     c[q++] = b[p++];
   } while(p<m);
  Â
   System.out.println("1st array: ");
   for(i=0; i<n; i++)
     System.out.print(a[i] + " ");
    Â
   System.out.println("\n 2nd array: ");
   for(i=0; i<m; i++)
     System.out.print(b[i] + " ");
    Â
   System.out.println("\n Sorted Array: ");
   for(i=0; i<q; i++)
     System.out.print(c[i] + " ");
  Â
 }
}
Explanation:
- First of all create objects of File  i.e. file1 and file2.
- Read from first file  and sort the first array .
- Read from second file  and sort the second array
- Merge two sub-arrays  in the form of concatenation.
- Finally display the arrays .