//How to merge two Array?
public class JoinArray {
public static void main(String[] args) {
int a[]= {1,2,3,4,5};
int b[]= {100,200,300,400,500};
int c[]= new int[a.length+b.length];
int count=0;
for(int i=0;i<a.length;i++)
{
c[i]=a[i];
count++;
}
public static void main(String[] args) {
int a[]= {1,2,3,4,5};
int b[]= {100,200,300,400,500};
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];
}
System.out.println("-----------c array--------------");
for(int k=0;k<c.length;k++)
{
System.out.println(c[k]);
}
}
for(int k=0;k<c.length;k++)
{
System.out.println(c[k]);
}
}
}
o/p view:----------------------
-----------c array--------------
1
2
3
4
5
100
200
300
400
500
1
2
3
4
5
100
200
300
400
500
No comments:
Post a Comment