In: Computer Science
6. Write a program in java which has two arays of size 4 and 5; merge them and sort.
The Java code:
import java.util.Arrays; 
public class Main {
   public static void main(String[] args) {
      int[]a = {1,2,3,4};
      int[]b = {30,16,13,21,73};
      int[]c = new int[a.length+b.length];
      int count = 0;
      
      for(int i = 0; i < a.length; i++) { 
         c[i] = a[i];
         count++;
      } 
      for(int j = 0; j < b.length;j++) { 
         c[count++] = b[j];
      } 
      for(int i = 0;i < c.length;i++) 
        System.out.print(c[i]+" ");
        
    Arrays.sort(c); 
  
    System.out.printf("\nSorted Merged Array : %s", Arrays.toString(c)); 
   } 
}
