ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Scala program to concatenate two integer arrays

Here, we are going to learn how to concatenate two integer arrays in Scala programming language?
Submitted by Nidhi, on May 07, 2021

Problem Solution:

Here, we will create two arrays of integer elements. And, we will concatenate both arrays using the Array.concat() method and then print the concatenated array elements on the console screen.

Program/Source Code:

The source code to concatenate two integer arrays is given below. The given program is compiled and executed on the ubuntu 18.04 operating system successfully.

// Scala program to concatenate two integer arrays

object Sample {  
    def main(args: Array[String]) {  
        var IntArr1 = Array(10, 20, 30, 40,50)
        var IntArr2 = Array(60, 70)
        
        // Concatenate two integer arrays
        var IntArr3 = Array.concat( IntArr1, IntArr2)
        
        println("Array element are: ")
        for ( item <- IntArr3 ) 
        {
            printf("%d ", item)
        }
        
        println()
    }
}

Output:

Array element are: 
10 20 30 40 50 60 70 

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 array IntArr1, IntArr2. Then we concatenated both arrays using the Array.concat() method and assigned the result into the IntArr3 array. After that, we printed the elements of IntArr3 elements on the console screen.

Scala Array Programs »

ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.