The source code to merge two integer arrays into a third array is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
// Scala program to merge two integer arrays
// into third array
object Sample {
def main(args: Array[String]) {
var IntArray1 = Array(10,11,12,13,14,15)
var IntArray2 = Array(20,21,22,23,24,25)
var IntArray3 = new Array[Int](12)
var count:Int=0
var count1:Int=0
// Merge IntArray1 and IntArray2 into IntArray3.
while(count<12)
{
if(count<6)
IntArray3(count)=IntArray1(count)
else
{
IntArray3(count)=IntArray2(count1)
count1=count1+1
}
count=count+1
}
println("Elements of merged array:")
count=0
while(count<12)
{
printf("%d ",IntArray3(count))
count=count+1
}
println()
}
}
Output:
Elements of merged array:
10 11 12 13 14 15 20 21 22 23 24 25
Explanation:
In the above program, we used an object-oriented approach to create the program. We created an object Sample, and we defined main() function. The main() function is the entry point for the program.
In the main() function, we created two integer arrays IntArray1, IntArray2. Both arrays contain 6-6 elements. Then we merged elements of both arrays into a third array IntArray3. After that, we printed the elements of the merged array on the console screen.
Program/Source Code:
The source code to merge two integer arrays into a third array is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.
Output:
Explanation:
In the above program, we used an object-oriented approach to create the program. We created an object Sample, and we defined main() function. The main() function is the entry point for the program.
In the main() function, we created two integer arrays IntArray1, IntArray2. Both arrays contain 6-6 elements. Then we merged elements of both arrays into a third array IntArray3. After that, we printed the elements of the merged array on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer