How To Merge Two Arrays In Java (Click On Full View ↑)

How To Merge Two Arrays In Java

-------------------------------------------------------------------------------------

 public class Merge
{
    public static void main(String[] args)
 {


    int[] arr1= {2,4,6,7,8};
    int[] arr2= {3,5,9,1};


    int a=arr1.length;
    int b=arr2.length;


    int[] res=new int[a+b];
   

    for(int i=0; i<arr1.length; i++)
    {
        res[i]=arr1[i];
    }


    for(int j=0; j<arr2.length; j++)
    {
        res[a+j]=arr2[j];

    }


    for(int k=0; k<res.length; k++)
    {
         System.out.print(res[k]+",");
    }

    }

}

-----------------------------------------------------------------------------------

Output :

2,4,6,7,8,3,5,9,1,

Comments

Popular posts from this blog

Mr. Myers wants to edit the marks assigned to the questions

Genral Ability

Object Orinted Programing