object Scala_Array {
def main(args: Array[String]): Unit = {
var nums1 = Array(2,4,5,7,9)
var nums2 = Array(2,3,5,6,9)
//Call the following Java class for some array operation
import java.util.Arrays;
println("Original Array1 : "+Arrays.toString(nums1));
println("Original Array2 : "+Arrays.toString(nums2));
println("Common elements of the said two arrays:")
var i = 0
var j =0;
for (i <- 0 to nums1.length-1)
{
j=0
for (j <- 0 to nums2.length-1)
{
if(nums1(i) == nums2(j))
{
print(s"${nums1(i)}, ")
}
}
}
}
}
Sample Output:
Original Array1 : [2, 4, 5, 7, 9]
Original Array2 : [2, 3, 5, 6, 9]
Common elements of the said two arrays:
2, 5, 9,
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer