Q:

Write a Scala program to check a given list is a palindrome or not

0

Write a Scala program to check a given list is a palindrome or not.

All Answers

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

object Scala_List {
  
  def is_Palindrome[A](list_nums: List[A]):Boolean = {
    list_nums == list_nums.reverse
}
     
   def main(args: Array[String]): Unit = {
         println("Result: " + is_Palindrome(List(1,2,3,4,3,2,1)));
         println("Result: " + is_Palindrome(List(1,2,3)));
       }
}

Sample Output:

Result: true
Result: 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