0
How to merge them
int a[]={1,6,4,22,9} int b[]={5,3,18,10,7} and explain me plz
3 Respuestas
0
simple approuch:
// You create a new array with the size of your 2 arrays combined, so that all integers have space.
int c[] = new int[a.length + b.length] {};
// You place each integer of a at the same index in c.
for(int i = 0; i < a.length; i++)
{
c[i] = a[i];
}
// You place each integer of b in a offset of a's size in c, so that you don't override the integers of a
for(int i = 0; i < b.lenght; i++)
{
c[i + a.length] = b[i];
}
0
whats that offset of a size I didn't get u
0
When you start from the beginning (index = 0) you will override all integers of array a. That's why you begin with an offset, which is a's size (= 5). The start index has to be 5, this is where the array is not occupied.