For double dimensional array programs click
https://java4school.com/double-dimensional-arraymatrix-programs-part-i

Write a program to accept two arrays from the user and merge them.
import java.io.*;
class merge
{
 public static void main()throws IOException
 {
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 System.out.println("Enter the length of the first array");
 int n=Integer.parseInt(br.readLine());
 int Arr1[]=new int[n];
 System.out.println("Enter the length of the second array");
 int m=Integer.parseInt(br.readLine());
 int Arr2[]=new int[m];
 int merge=m+n;
 int Arr3[]=new int[merge];
 System.out.println("Enter the values for the first array");
 for(int i=0;i<n;i++)
 Arr1[i]=Integer.parseInt(br.readLine());
 System.out.println("Enter the values for the second array");
 for(int i=0;i<m;i++)
 Arr2[i]=Integer.parseInt(br.readLine());
 for(int i=0;i<n;i++)
 Arr3[i]=Arr1[i];
 for(int i=0;i<m;i++)
 Arr3[n+i]=Arr2[i];
 System.out.println("The merged array is");
 for(int i=0;i<merge;i++)
 System.out.print(Arr3[i]+"\t");
 } }

Output:
Enter the length of the first array
4
Enter the length of the second array
3
Enter the values for the first array
4
3
7
Enter the values for the second array
8
9
2
The merged array is
4 3 7 8 9 2

For more java videos
https://www.youtube.com/user/trushnatej

LEAVE A REPLY

Please enter your comment!
Please enter your name here