Q:

Write a Scala program to check whether the value of the fast or last element of two given array ( length 1 or more) of integers are same or not

0

Write a Scala program to check whether the value of the fast or last element of two given array ( length 1 or more) of integers are same or not.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_Array
{
  def test(x: Array[Int], y: Array[Int]): Boolean = {
    if (x.length < 1 || y.length < 1) false 
    else (x.head == y.head) || (x.last == y.last)
  }
  
  
  def main(args: Array[String]): Unit = 
 {
   println(test(Array(1,2,3,4), Array(2,3,4)))
   println(test(Array(1,2,3,4), Array(1,3,4)))
   println(test(Array(1,2,3,4), Array(1,3,4,5)))
   println(test(Array(2,2,3,4), Array(1,3,4,5)))
  }
}

Sample Output:

true
true
true
false

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now