The following program demonstrates how to Create an Array Using the Elements of the Two Arrays in Java.

In this program, we have two arrays of three elements each as the input. The output is produced by taking the middle element of each array and create a new two element array.

So, we just create an array of two elements and assign the elements at the index 1 from each of the input array to its two respective elements.

public class Exercise12
{
	public static void main(String[] args) {
	      //int[] arr1={1, 2, 3};
	      //int[] arr2={4, 5, 6};
	      //int[] arr1={7, 7, 7};
	      //int[] arr2={3, 8, 0};
	      int[] arr1={5, 2, 9};
	      int[] arr2={1, 4, 5};

	    System.out.println("Array 1 Elements...");
	    for(int i=0;i<arr1.length;i++)
	    {
		System.out.print(arr1[i]+"\t");
            }
	    System.out.println("\nArray 2 Elements...");
	    for(int i=0;i<arr2.length;i++)
	    {
		System.out.print(arr2[i]+"\t");
            }
	    int[] arr3=new int[2];
	    arr3[0]=arr1[1];
	    arr3[1]=arr2[1];
	    System.out.println("\nArray 3 Elements...");
	    for(int i=0;i<arr3.length;i++)
	    {   
		System.out.print(arr3[i]+"\t");
            }
	}
}

Output

A Program to Create an Array Using the Elements of the Two Arrays in Java
A Program to Create an Array Using the Elements of the Two Arrays in Java

Further Reading

Java Practice Exercise

programmingempire

Princites